From b759a344318431fb0f0f1fdbbb102bc2b6e4c022 Mon Sep 17 00:00:00 2001 From: Andy Davidoff Date: Wed, 11 Nov 2020 11:50:11 -0500 Subject: [PATCH] 0.4.0: add simple find --- grok | 2 +- skiplists.nim | 26 ++------------------------ skiplists.nimble | 2 +- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/grok b/grok index dbbfca0..b57451f 160000 --- a/grok +++ b/grok @@ -1 +1 @@ -Subproject commit dbbfca04eef881d88fcfd906e6852ba74ac93ecb +Subproject commit b57451f416ebe63cbc2b3b7d87bc80debc24d7b8 diff --git a/skiplists.nim b/skiplists.nim index 03f9fce..6dc2154 100644 --- a/skiplists.nim +++ b/skiplists.nim @@ -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` diff --git a/skiplists.nimble b/skiplists.nimble index 4f72d9c..8966fdf 100644 --- a/skiplists.nimble +++ b/skiplists.nimble @@ -1,4 +1,4 @@ -version = "0.3.0" +version = "0.4.0" author = "disruptek" description = "skiplists" license = "MIT"