Changes to README
This commit is contained in:
parent
e2e66db49b
commit
49d7ae6c8e
34
README.md
34
README.md
|
@ -19,26 +19,26 @@ import nimdeque
|
||||||
|
|
||||||
queue = newLinkedDeque[int]()
|
queue = newLinkedDeque[int]()
|
||||||
|
|
||||||
# Appends at the end
|
# Appends to the tail
|
||||||
queue.add(1)
|
queue.add(1)
|
||||||
queue.add(2)
|
queue.add(2)
|
||||||
queue.add(3)
|
queue.add(3)
|
||||||
|
|
||||||
# Prepends at the beginning
|
# Prepends to the head
|
||||||
queue.addLeft(0)
|
queue.addLeft(0)
|
||||||
queue.addLeft(-1)
|
queue.addLeft(-1)
|
||||||
queue.addLeft(-2)
|
queue.addLeft(-2)
|
||||||
|
|
||||||
# Pops the first element in O(1) time
|
# Pops and returns the first element in O(1) time
|
||||||
queue.pop()
|
queue.pop()
|
||||||
|
|
||||||
# Pops the last element in O(1) time
|
# Pops and returns the last element in O(1) time
|
||||||
queue.pop(queue.high())
|
discard queue.pop(queue.high())
|
||||||
# This can also be written as
|
# This can also be written as
|
||||||
queue.pop(^1)
|
discard queue.pop(^1)
|
||||||
|
|
||||||
# Pops element at position n
|
# Pops element at position n
|
||||||
queue.pop(n)
|
discard queue.pop(n)
|
||||||
|
|
||||||
# Supports iteration
|
# Supports iteration
|
||||||
for i, e in queue:
|
for i, e in queue:
|
||||||
|
@ -49,15 +49,16 @@ for e in queue.reversed():
|
||||||
echo e
|
echo e
|
||||||
|
|
||||||
echo queue.len()
|
echo queue.len()
|
||||||
echo 5 in queue # false
|
5 in queue # false
|
||||||
echo 0 in queue # true
|
0 in queue # true
|
||||||
|
|
||||||
# Item accessing works just like regular sequence types in Nim.
|
# Item accessing works just like regular sequence types in Nim.
|
||||||
# Note that the further the item is from either end of the
|
# Note that the further the item is from either end of the
|
||||||
# queue, the higher the time it takes to retrieve it. For
|
# queue, the higher the time it takes to retrieve it. For
|
||||||
# fast random access, seqs should be used instead
|
# fast random access, seqs should be used instead
|
||||||
assert queue[0] == -1
|
queue[0] # -1
|
||||||
assert queue[^1] == queue[queue.high()]
|
queue[^1]
|
||||||
|
queue[queue.high()]
|
||||||
|
|
||||||
# It's possible to extend a deque with other deques or with seqs
|
# It's possible to extend a deque with other deques or with seqs
|
||||||
# of compatible type
|
# of compatible type
|
||||||
|
@ -67,6 +68,13 @@ other.add(10)
|
||||||
queue.extend(@[5, 6, 7, 8])
|
queue.extend(@[5, 6, 7, 8])
|
||||||
queue.extend(other)
|
queue.extend(other)
|
||||||
|
|
||||||
|
# Finds the first occurrence of an
|
||||||
|
# item in the queue, returns -1 if not
|
||||||
|
# found
|
||||||
|
|
||||||
|
queue.find(9999) # -1, not found
|
||||||
|
queue.find(-1) # 0
|
||||||
|
|
||||||
# Clears the queue in O(1) time
|
# Clears the queue in O(1) time
|
||||||
queue.clear()
|
queue.clear()
|
||||||
# Clears the queue in O(n) time
|
# Clears the queue in O(n) time
|
||||||
|
@ -100,7 +108,9 @@ some benchmarks as well as the test suite used to validate the behavior of the q
|
||||||
1. I was bored during my programming class
|
1. I was bored during my programming class
|
||||||
2. That only provides a deque based on `seq`s
|
2. That only provides a deque based on `seq`s
|
||||||
3. The deque in that module is a value type
|
3. The deque in that module is a value type
|
||||||
4. I was bored during my programming class
|
4. The deques in this module allow accessing at arbirary locations
|
||||||
|
5. More useful procs are implemented
|
||||||
|
1. I was bored during my programming class
|
||||||
|
|
||||||
|
|
||||||
## Performance against a regular seq
|
## Performance against a regular seq
|
||||||
|
|
Loading…
Reference in New Issue