Skip to content

Commit

Permalink
0.4.0: add simple find
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Nov 11, 2020
1 parent 23a1e63 commit b759a34
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
2 changes: 1 addition & 1 deletion grok
Submodule grok updated 7 files
+0 −3 README.md
+1 −7 grok.nim
+0 −5 grok.nimble
+0 −10 grok/json.nim
+0 −22 grok/log.nim
+0 −14 grok/mem.nim
+0 −65 grok/time.nim
26 changes: 2 additions & 24 deletions skiplists.nim
Original file line number Diff line number Diff line change
Expand Up @@ -326,30 +326,8 @@ proc find*[T](s: SkipList[T]; value: SkipList[T]; r: var SkipList[T];
compare: SkipListCmp[T] = `<>`): bool =
## Find the SkipList `value` in SkipList `s`, storing the result in `r`;
## returns `true` if the value was found, else `false`.
when true:
func finder(s: SkipList[T]): cmp = compare(value, s)
result = s.find(r, compare = finder)
else:
if not s.isNil:
r = s
if compare(value, r) == Equal:
result = true
else:
while true:
case compare(value, r.over)
of Undefined:
if r.down.isNil:
break
else:
r = r.down
of More:
r = r.over
of Equal:
r = r.over
result = true
break
of Less:
raise newException(SkipListDefect, "out of order")
func finder(s: SkipList[T]): cmp = compare(value, s)
result = s.find(r, compare = finder)

proc find*[T](s: SkipList[T]; value: T): SkipList[T] =
## Find the SkipList holding `value` in SkipList `s`; raises a KeyError`
Expand Down
2 changes: 1 addition & 1 deletion skiplists.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.3.0"
version = "0.4.0"
author = "disruptek"
description = "skiplists"
license = "MIT"
Expand Down

0 comments on commit b759a34

Please sign in to comment.