update code
This commit is contained in:
parent
e58a65369b
commit
1542e5bf48
8 changed files with 87 additions and 40 deletions
3
examples/.gitignore
vendored
Normal file
3
examples/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# these files are auto-derived from the skiplist example
|
||||
skiplist-1-4.p3l
|
||||
skiplist-3-8.p3l
|
|
@ -239,19 +239,20 @@ fn skiplist_insert<V>(
|
|||
|
||||
// NOT PUBLIC API
|
||||
// Find a value in the skiplist, starting the search at a specific node.
|
||||
// Return the value along with the path length of the search.
|
||||
fn skiplist_get_impl<V>(
|
||||
node: SkipListNode<V>,
|
||||
key: int
|
||||
) -> (Option<V>, int) {
|
||||
let steps: int = 1;
|
||||
let pathlen: int = 1;
|
||||
|
||||
if (*node).3 < key {
|
||||
while true {
|
||||
if let Some(next) = (*node).2 {
|
||||
let next_key: int = (*next).3;
|
||||
steps = steps + 1;
|
||||
if next_key <= key {
|
||||
node = next;
|
||||
pathlen = pathlen + 1;
|
||||
if next_key == key {
|
||||
break;
|
||||
} else {
|
||||
|
@ -270,26 +271,26 @@ fn skiplist_get_impl<V>(
|
|||
}
|
||||
|
||||
if (*node).3 != key {
|
||||
return (None, steps);
|
||||
return (None, pathlen);
|
||||
}
|
||||
|
||||
// the value is only stored at the lowest level
|
||||
while let Some(below) = (*node).1 {
|
||||
node = below;
|
||||
}
|
||||
return (Some(unwrap::<V>((*node).4)), steps);
|
||||
return (Some(unwrap::<V>((*node).4)), pathlen);
|
||||
}
|
||||
|
||||
// Find a value in the skiplist.
|
||||
// Find a value in the skiplist. Return the value along with the path
|
||||
// length of the search.
|
||||
fn skiplist_get<V>(list: SkipList<V>, key: int) -> (Option<V>, int) {
|
||||
let steps: int = 0;
|
||||
let pathlen: int = 0;
|
||||
|
||||
while true {
|
||||
if let Some(node) = list.2 {
|
||||
steps = steps + 1;
|
||||
if (*node).3 <= key {
|
||||
let tmp: (Option<V>, int) = skiplist_get_impl::<V>(node, key);
|
||||
return (tmp.0, steps + tmp.1);
|
||||
return (tmp.0, pathlen + tmp.1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +299,7 @@ fn skiplist_get<V>(list: SkipList<V>, key: int) -> (Option<V>, int) {
|
|||
continue;
|
||||
}
|
||||
|
||||
return (None, steps);
|
||||
return (None, pathlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,8 +376,8 @@ let _unit: () = assert_in_range(key, 0, len);
|
|||
let lookup: (Option<()>, int) = skiplist_get::<()>(list, key);
|
||||
let _unit: () = unwrap::<()>(lookup.0);
|
||||
|
||||
let steps: int = lookup.1;
|
||||
let pathlen: int = lookup.1;
|
||||
let lvl: int = skiplist_level::<()>(list);
|
||||
|
||||
output!(len);
|
||||
output!(lvl, steps);
|
||||
output!(lvl, pathlen);
|
||||
|
|
|
@ -239,19 +239,20 @@ fn skiplist_insert<V>(
|
|||
|
||||
// NOT PUBLIC API
|
||||
// Find a value in the skiplist, starting the search at a specific node.
|
||||
// Return the value along with the path length of the search.
|
||||
fn skiplist_get_impl<V>(
|
||||
node: SkipListNode<V>,
|
||||
key: int
|
||||
) -> (Option<V>, int) {
|
||||
let steps: int = 1;
|
||||
let pathlen: int = 1;
|
||||
|
||||
if (*node).3 < key {
|
||||
while true {
|
||||
if let Some(next) = (*node).2 {
|
||||
let next_key: int = (*next).3;
|
||||
steps = steps + 1;
|
||||
if next_key <= key {
|
||||
node = next;
|
||||
pathlen = pathlen + 1;
|
||||
if next_key == key {
|
||||
break;
|
||||
} else {
|
||||
|
@ -270,26 +271,26 @@ fn skiplist_get_impl<V>(
|
|||
}
|
||||
|
||||
if (*node).3 != key {
|
||||
return (None, steps);
|
||||
return (None, pathlen);
|
||||
}
|
||||
|
||||
// the value is only stored at the lowest level
|
||||
while let Some(below) = (*node).1 {
|
||||
node = below;
|
||||
}
|
||||
return (Some(unwrap::<V>((*node).4)), steps);
|
||||
return (Some(unwrap::<V>((*node).4)), pathlen);
|
||||
}
|
||||
|
||||
// Find a value in the skiplist.
|
||||
// Find a value in the skiplist. Return the value along with the path
|
||||
// length of the search.
|
||||
fn skiplist_get<V>(list: SkipList<V>, key: int) -> (Option<V>, int) {
|
||||
let steps: int = 0;
|
||||
let pathlen: int = 0;
|
||||
|
||||
while true {
|
||||
if let Some(node) = list.2 {
|
||||
steps = steps + 1;
|
||||
if (*node).3 <= key {
|
||||
let tmp: (Option<V>, int) = skiplist_get_impl::<V>(node, key);
|
||||
return (tmp.0, steps + tmp.1);
|
||||
return (tmp.0, pathlen + tmp.1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +299,7 @@ fn skiplist_get<V>(list: SkipList<V>, key: int) -> (Option<V>, int) {
|
|||
continue;
|
||||
}
|
||||
|
||||
return (None, steps);
|
||||
return (None, pathlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,8 +376,8 @@ let _unit: () = assert_in_range(key, 0, len);
|
|||
let lookup: (Option<()>, int) = skiplist_get::<()>(list, key);
|
||||
let _unit: () = unwrap::<()>(lookup.0);
|
||||
|
||||
let steps: int = lookup.1;
|
||||
let pathlen: int = lookup.1;
|
||||
let lvl: int = skiplist_level::<()>(list);
|
||||
|
||||
output!(len);
|
||||
output!(lvl, steps);
|
||||
output!(lvl, pathlen);
|
||||
|
|
|
@ -239,19 +239,20 @@ fn skiplist_insert<V>(
|
|||
|
||||
// NOT PUBLIC API
|
||||
// Find a value in the skiplist, starting the search at a specific node.
|
||||
// Return the value along with the path length of the search.
|
||||
fn skiplist_get_impl<V>(
|
||||
node: SkipListNode<V>,
|
||||
key: int
|
||||
) -> (Option<V>, int) {
|
||||
let steps: int = 1;
|
||||
let pathlen: int = 1;
|
||||
|
||||
if (*node).3 < key {
|
||||
while true {
|
||||
if let Some(next) = (*node).2 {
|
||||
let next_key: int = (*next).3;
|
||||
steps = steps + 1;
|
||||
if next_key <= key {
|
||||
node = next;
|
||||
pathlen = pathlen + 1;
|
||||
if next_key == key {
|
||||
break;
|
||||
} else {
|
||||
|
@ -270,26 +271,26 @@ fn skiplist_get_impl<V>(
|
|||
}
|
||||
|
||||
if (*node).3 != key {
|
||||
return (None, steps);
|
||||
return (None, pathlen);
|
||||
}
|
||||
|
||||
// the value is only stored at the lowest level
|
||||
while let Some(below) = (*node).1 {
|
||||
node = below;
|
||||
}
|
||||
return (Some(unwrap::<V>((*node).4)), steps);
|
||||
return (Some(unwrap::<V>((*node).4)), pathlen);
|
||||
}
|
||||
|
||||
// Find a value in the skiplist.
|
||||
// Find a value in the skiplist. Return the value along with the path
|
||||
// length of the search.
|
||||
fn skiplist_get<V>(list: SkipList<V>, key: int) -> (Option<V>, int) {
|
||||
let steps: int = 0;
|
||||
let pathlen: int = 0;
|
||||
|
||||
while true {
|
||||
if let Some(node) = list.2 {
|
||||
steps = steps + 1;
|
||||
if (*node).3 <= key {
|
||||
let tmp: (Option<V>, int) = skiplist_get_impl::<V>(node, key);
|
||||
return (tmp.0, steps + tmp.1);
|
||||
return (tmp.0, pathlen + tmp.1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +299,7 @@ fn skiplist_get<V>(list: SkipList<V>, key: int) -> (Option<V>, int) {
|
|||
continue;
|
||||
}
|
||||
|
||||
return (None, steps);
|
||||
return (None, pathlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,8 +376,8 @@ let _unit: () = assert_in_range(key, 0, len);
|
|||
let lookup: (Option<()>, int) = skiplist_get::<()>(list, key);
|
||||
let _unit: () = unwrap::<()>(lookup.0);
|
||||
|
||||
let steps: int = lookup.1;
|
||||
let pathlen: int = lookup.1;
|
||||
let lvl: int = skiplist_level::<()>(list);
|
||||
|
||||
output!(len);
|
||||
output!(lvl, steps);
|
||||
output!(lvl, pathlen);
|
||||
|
|
Reference in a new issue