mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-10 06:47:34 +00:00
purge ufind
This commit is contained in:
parent
81caf926b4
commit
f9aef928ca
@ -15,7 +15,7 @@ import core::*;
|
|||||||
|
|
||||||
export net, uv;
|
export net, uv;
|
||||||
export c_vec, util, timer;
|
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 rope, arena;
|
||||||
export ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint;
|
export ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint;
|
||||||
export test, tempfile, serialization;
|
export test, tempfile, serialization;
|
||||||
@ -49,8 +49,6 @@ mod rope;
|
|||||||
mod smallintmap;
|
mod smallintmap;
|
||||||
mod sort;
|
mod sort;
|
||||||
mod treemap;
|
mod treemap;
|
||||||
mod ufind;
|
|
||||||
|
|
||||||
|
|
||||||
// And ... other stuff
|
// And ... other stuff
|
||||||
|
|
||||||
|
@ -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; }
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
import std::{ufind, map, smallintmap};
|
import std::{map, smallintmap};
|
||||||
import result::result;
|
import result::result;
|
||||||
import std::map::hashmap;
|
import std::map::hashmap;
|
||||||
import driver::session;
|
import driver::session;
|
||||||
|
@ -61,7 +61,6 @@ import std::smallintmap::map;
|
|||||||
import std::map;
|
import std::map;
|
||||||
import std::map::{hashmap, int_hash};
|
import std::map::{hashmap, int_hash};
|
||||||
import std::serialization::{serialize_uint, deserialize_uint};
|
import std::serialization::{serialize_uint, deserialize_uint};
|
||||||
import std::ufind;
|
|
||||||
import vec::each;
|
import vec::each;
|
||||||
import syntax::print::pprust::*;
|
import syntax::print::pprust::*;
|
||||||
import util::common::{indent, indenter};
|
import util::common::{indent, indenter};
|
||||||
|
Loading…
Reference in New Issue
Block a user