Skip to content

Commit

Permalink
add index remove and count methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBoyce committed Oct 14, 2024
1 parent e9b1c26 commit e5366ad
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions NumpyDeque/NumpyDeque.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,50 @@ def where(self, value):
"""
return np.where(self.deque == value)[0]

def index(self, value, start=0, stop=None):
"""
Return the deque index of value (at or after index start and before index stop).
Returns the first match
Parameters:
value: The value to search for.
Returns:
int: The the first index that value is found at.
"""
p = self.where(value)
if len(p) > 0:
if stop is None:
stop = self.size
for i in p:
if start <= i < stop:
return i
return None

def remove(self, value):
"""
Remove the first occurrence of value.
Parameters:
value: The value to search for.
"""
i = self.index(value)
if i is not None:
self.drop(i)

def count(self, value):
"""
Count the number of deque elements equal to value.
Parameters:
value: The value that is being counted.
Returns:
int: The count.
"""
return np.count_nonzero(self.deque == value)

def __getitem__(self, index):
return self.queue[index]

Expand Down

0 comments on commit e5366ad

Please sign in to comment.