diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-05-12 19:29:02 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-05-18 20:00:50 -0700 |
| commit | f9aef928ca49861c9711c0f832abac2cfb40ee47 (patch) | |
| tree | 05834b08358aa89ab9949825e624252e8587b343 /src/libstd | |
| parent | 81caf926b4ecf9a6c48f2f7ade2102e8876e6677 (diff) | |
| download | rust-f9aef928ca49861c9711c0f832abac2cfb40ee47.tar.gz rust-f9aef928ca49861c9711c0f832abac2cfb40ee47.zip | |
purge ufind
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/std.rc | 4 | ||||
| -rw-r--r-- | src/libstd/ufind.rs | 52 |
2 files changed, 1 insertions, 55 deletions
diff --git a/src/libstd/std.rc b/src/libstd/std.rc index d1b578f3d87..40a03ae25c2 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -15,7 +15,7 @@ import core::*; export net, uv; export c_vec, util, timer; -export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap, ufind; +export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap; export rope, arena; export ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint; export test, tempfile, serialization; @@ -49,8 +49,6 @@ mod rope; mod smallintmap; mod sort; mod treemap; -mod ufind; - // And ... other stuff diff --git a/src/libstd/ufind.rs b/src/libstd/ufind.rs deleted file mode 100644 index 9a7483553dc..00000000000 --- a/src/libstd/ufind.rs +++ /dev/null @@ -1,52 +0,0 @@ - -import core::option; -import option::{some, none}; - - -// A very naive implementation of union-find with unsigned integer nodes. -// Maintains the invariant that the root of a node is always equal to or less -// than the node itself. -type node = option<uint>; - -type ufind = {mut nodes: [mut node]}; - -fn make() -> ufind { ret {mut nodes: [mut]}; } - -fn make_set(ufnd: ufind) -> uint { - let idx = vec::len(ufnd.nodes); - ufnd.nodes += [mut none::<uint>]; - ret idx; -} - - -/// Creates sets as necessary to ensure that least `n` sets are present in the -/// data structure. -fn grow(ufnd: ufind, n: uint) { - while set_count(ufnd) < n { make_set(ufnd); } -} - -fn find(ufnd: ufind, n: uint) -> uint { - alt ufnd.nodes[n] { - none { ret n; } - some(m) { let m_ = m; ret find(ufnd, m_); } - } -} - -fn union(ufnd: ufind, m: uint, n: uint) { - let m_root = find(ufnd, m); - let n_root = find(ufnd, n); - if m_root < n_root { - ufnd.nodes[n_root] = some::<uint>(m_root); - } else if m_root > n_root { ufnd.nodes[m_root] = some::<uint>(n_root); } -} - -fn set_count(ufnd: ufind) -> uint { ret vec::len::<node>(ufnd.nodes); } - - -// Removes all sets with IDs greater than or equal to the given value. -fn prune(ufnd: ufind, n: uint) { - // TODO: Use "slice" once we get rid of "const" - - let mut len = vec::len::<node>(ufnd.nodes); - while len != n { vec::pop::<node>(ufnd.nodes); len -= 1u; } -} |
