-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BTrees in Motoko. #396
base: master
Are you sure you want to change the base?
BTrees in Motoko. #396
Changes from 1 commit
c35b3d9
b95320f
d81a1c3
142a0d0
ffd99ec
61334ec
0d06506
273fb6f
9db84ca
4393a81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import A "Array"; | ||
import I "Iter"; | ||
import List "List"; | ||
import Text "Text"; | ||
import Option "Option"; | ||
import Order "Order"; | ||
import P "Prelude"; | ||
|
@@ -45,7 +46,7 @@ module { | |
switch t { | ||
case (#leaf(d)) { return find_data<K, V>(d, k, c) }; | ||
case (#internal(i)) { | ||
for (j in I.range(0, i.data.size())) { | ||
for (j in I.range(0, i.data.size() - 1)) { | ||
switch (c(k, i.data[j].0)) { | ||
case (#equal) { return ?i.data[j].1 }; | ||
case (#less) { return find<K, V>(i.trees[j], k, c) }; | ||
|
@@ -57,14 +58,37 @@ module { | |
}; | ||
}; | ||
|
||
public module Insert { | ||
|
||
|
||
|
||
}; | ||
|
||
// Assert that the given B-Tree instance observes all relevant invariants. | ||
// Used for unit tests. Show function helps debug failing tests. | ||
// | ||
// Note: These checks-as-assertions can be refactored into value-producing checks, | ||
// if that seems useful. Then, they can be individual matchers tests. Again, if useful. | ||
public func assertIsValid<K, V>( | ||
t : Tree<K, V>, | ||
compare : (K, K) -> Order.Order, | ||
show : K -> Text) | ||
{ | ||
Check.root<K, V>({compare; show}, t) | ||
}; | ||
|
||
public func assertIsValidTextKeys<V>(t : Tree<Text, V>){ | ||
Check.root<Text, V>({compare=Text.compare; show=func (t:Text) : Text { t }}, t) | ||
}; | ||
|
||
/// Check that a B-Tree instance observes invariants of B-Trees. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this module is just for testing/debugging, should When I import the default BTree module like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This module is static. The compiler will not compile static code that you import but do not use. (However, class instances will always contain all methods, regardless of usage. Not applicable here.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why? It's more enclosed and encapsulated here. There is no way to "hide" a top-level module in |
||
/// Invariants ensure performance is what we expect. | ||
/// For testing and debugging. | ||
/// | ||
/// Future refactoring --- Eventually, we can return Result or | ||
/// Option so that both valid and invalid inputs can be inspected in | ||
/// test cases. Doing assertions directly here is easier, for now. | ||
public module Check { | ||
module Check { | ||
|
||
type Inf<K> = {#infmax; #infmin; #finite : K}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it help if
Check
and these test methods were just moved intotest/BTreeTest.mo
?