|
33 | 33 | value: T
|
34 | 34 | SkipList*[T] = ref SkipListObj[T]
|
35 | 35 |
|
| 36 | + SkipListCmp*[T] = proc(a, b: SkipList[T]): cmp {.noSideEffect.} ## |
| 37 | + ## The procedure signature to use for comparing two SkipLists. |
| 38 | + |
36 | 39 | SkipListPred*[T] = proc(up: SkipList[T]; here: SkipList[T];
|
37 | 40 | child: SkipList[T]): bool ##
|
38 | 41 | ## The predicate used to determine whether the SkipList
|
@@ -98,15 +101,16 @@ template `=!=`*(a, b: SkipList): bool =
|
98 | 101 | ## `false` if SkipLists `a` and `b` share the same memory, else `true`.
|
99 | 102 | not(a === b)
|
100 | 103 |
|
101 |
| -template `<>`(a, b: SkipListObj): cmp = |
| 104 | +func `<>`[T](a, b: SkipListObj[T]): cmp = |
| 105 | + ## Compare SkipListObj `a` and `b`. |
102 | 106 | if a.value < b.value:
|
103 | 107 | Less
|
104 | 108 | elif a.value == b.value:
|
105 | 109 | Equal
|
106 | 110 | else:
|
107 | 111 | More
|
108 | 112 |
|
109 |
| -template `<>`(a, b: SkipList): cmp = |
| 113 | +func `<>`[T](a, b: SkipList[T]): cmp = |
110 | 114 | ## Compare SkipList `a` and `b`.
|
111 | 115 | if a.isNil or b.isNil:
|
112 | 116 | if a.isNil and b.isNil:
|
@@ -203,7 +207,7 @@ proc `$`(s: SkipList): string {.raises: [].} =
|
203 | 207 | result.add $s.down
|
204 | 208 |
|
205 | 209 | when defined(release) or not skiplistsChecks:
|
206 |
| - template check(s: SkipList; args: varargs[string, `$`]) = discard |
| 210 | + template check(s: SkipList; args: varargs[untyped]) = discard |
207 | 211 | else:
|
208 | 212 | import std/strutils
|
209 | 213 |
|
@@ -288,16 +292,17 @@ proc hash*(s: SkipList): Hash =
|
288 | 292 | h = h !& hash(item)
|
289 | 293 | result = !$h
|
290 | 294 |
|
291 |
| -proc find[T](s: SkipList[T]; value: SkipList[T]; r: var SkipList[T]): bool = |
| 295 | +proc find[T](s: SkipList[T]; value: SkipList[T]; r: var SkipList[T]; |
| 296 | + compare: SkipListCmp[T] = `<>`): bool = |
292 | 297 | ## Find the SkipList `value` in SkipList `s`, storing the result in `r`;
|
293 | 298 | ## returns `true` if the value was found, else `false`.
|
294 | 299 | if not s.isNil:
|
295 | 300 | r = s
|
296 |
| - if value <> r == Equal: |
| 301 | + if compare(value, r) == Equal: |
297 | 302 | result = true
|
298 | 303 | else:
|
299 | 304 | while true:
|
300 |
| - case value <> r.over |
| 305 | + case compare(value, r.over) |
301 | 306 | of Undefined:
|
302 | 307 | if r.down.isNil:
|
303 | 308 | break
|
|
0 commit comments