Bounds and queue size checking can now be disabled
This commit is contained in:
parent
eaaac53be0
commit
39a789b068
|
@ -107,6 +107,8 @@ queue.clearPop()
|
||||||
capabilities
|
capabilities
|
||||||
- The objects in this module are **all** tracked references! (Unlike the `std/deques` module which implements them as value
|
- The objects in this module are **all** tracked references! (Unlike the `std/deques` module which implements them as value
|
||||||
types and gives `var` variants of each procedure)
|
types and gives `var` variants of each procedure)
|
||||||
|
- As with the data structure implemented in `std/deques`, all bounds checking is disabled when compiled with
|
||||||
|
`--checks:off` or `-d:danger`, but queue size checking is not. To disable queue size checking, pass `-d:noQueueSizeCheck`
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
|
|
|
@ -83,10 +83,11 @@ proc maxSize*[T](self: LinkedDeque[T]): int =
|
||||||
proc getNode[T](self: LinkedDeque[T], i: int): DequeNode[T] {.raises: [IndexDefect, ValueError].} =
|
proc getNode[T](self: LinkedDeque[T], i: int): DequeNode[T] {.raises: [IndexDefect, ValueError].} =
|
||||||
## Low level method for indexing and getting
|
## Low level method for indexing and getting
|
||||||
## a node object back
|
## a node object back
|
||||||
if self.high() == -1:
|
when defined(boundChecks):
|
||||||
raise newException(IndexDefect, "LinkedDeque is empty")
|
if self.high() == -1:
|
||||||
elif i > self.high() or i < 0:
|
raise newException(IndexDefect, "LinkedDeque is empty")
|
||||||
raise newException(IndexDefect, &"{i} notin 0..{self.high()}")
|
elif i > self.high() or i < 0:
|
||||||
|
raise newException(IndexDefect, &"{i} notin 0..{self.high()}")
|
||||||
var pos = 0
|
var pos = 0
|
||||||
if i < self.high() div 2:
|
if i < self.high() div 2:
|
||||||
# If we're taking an element
|
# If we're taking an element
|
||||||
|
@ -217,8 +218,9 @@ proc insert*[T](self: LinkedDeque[T], pos: int, val: T) {.raises: [IndexDefect,
|
||||||
## to O(n) the closer the index gets to the middle of
|
## to O(n) the closer the index gets to the middle of
|
||||||
## the deque. This proc raises an IndexDefect if the
|
## the deque. This proc raises an IndexDefect if the
|
||||||
## queue's max size is reached
|
## queue's max size is reached
|
||||||
if self.maxSize > 0 and self.size == self.maxSize:
|
when not defined(noQueueSizeCheck):
|
||||||
raise newException(IndexDefect, &"LinkedDeque has reached its maximum size ({self.maxSize})")
|
if self.maxSize > 0 and self.size == self.maxSize:
|
||||||
|
raise newException(IndexDefect, &"LinkedDeque has reached its maximum size ({self.maxSize})")
|
||||||
if pos == 0:
|
if pos == 0:
|
||||||
self.addLeft(val)
|
self.addLeft(val)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue