unification_table

A module for unification table operations in data structures and algorithms.

data-structure
algorithm
unification
table
moon add BigOrangeQWQ/unification_table@0.1.2
Download zip
Version
0.1.2
License
Apache-2.0
Last updated
last year
Downloads
30
README

#UnificationTable

Note: Snapshot operations should follow a stack-like (LIFO) order. A root snapshot is required for snapshot operations. Avoid using the new_index method; use table.index to obtain the index instead.

///|
test "UnificationTable::union_test" {
let table = new(capacity=5)
for i in 0..<5 {
table.push(i)
}
let index1 = table.index(1)
let index2 = table.index(2)
let index3 = table.index(3)
assert_false!(table.unioned(index1, index2))
let _ = table.unite(index1, index2, 8)
assert_true!(table.unioned(index1, index2))
assert_false!(table.unioned(index1, index3))
assert_true!(table.unioned(index2, index1))
assert_false!(table.unioned(index2, index3))
}

#Snapshot

///|
test "UnificationTable::snapshot_unite_test" {
let table = new(capacity=5)
let _ = table.start_snapshot()
for i in 0..<5 {
table.push(i)
}
let s1 = table.start_snapshot()
let index1 = table.index(1)
let index2 = table.index(2)
let index3 = table.index(3)
assert_false!(table.unioned(index1, index2))
let _ = table.unite(index1, index2, 8)
assert_true!(table.unioned(index1, index2))
assert_false!(table.unioned(index1, index3))
assert_false!(table.unioned(index2, index3))
table.rollback_to(s1)
assert_false!(table.unioned(index1, index2))
assert_false!(table.unioned(index1, index3))
assert_false!(table.unioned(index2, index1))
}

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io