Skip to content

Commit

Permalink
remove copy
Browse files Browse the repository at this point in the history
  • Loading branch information
jialunzhang-psu committed Jan 17, 2025
1 parent abc8de9 commit c6abd24
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 51 deletions.
23 changes: 0 additions & 23 deletions immut/array/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,6 @@ pub fn of[A](arr : FixedArray[A]) -> T[A] {
makei(arr.length(), fn(i) { arr[i] })
}

///|
/// Physically copy the array.
/// Since it is an immutable data structure,
/// it is rarely the case that you would need this function.
pub fn copy[A](self : T[A]) -> T[A] {
fn copy(t : Tree[A]) -> Tree[A] {
match t {
Leaf(l) => Leaf(l.copy())
Empty => Empty
Node(node, sizes) =>
Node(
FixedArray::makei(node.length(), fn(i) { copy(node[i]) }),
match sizes {
Some(sizes) => Some(FixedArray::copy(sizes))
None => None
},
)
}
}

{ tree: copy(self.tree), size: self.size, shift: self.shift }
}

///|
/// Create a persistent array from an array.
///
Expand Down
1 change: 0 additions & 1 deletion immut/array/array.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fn of[A](FixedArray[A]) -> T[A]
type T
impl T {
concat[A](Self[A], Self[A]) -> Self[A]
copy[A](Self[A]) -> Self[A]
each[A](Self[A], (A) -> Unit) -> Unit
eachi[A](Self[A], (Int, A) -> Unit) -> Unit
fold[A, B](Self[A], init~ : B, (B, A) -> B) -> B
Expand Down
13 changes: 0 additions & 13 deletions immut/array/array_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,6 @@ test "length" {
inspect!(ve.length(), content="0")
}

test "copy" {
let v = @array.of([1, 2, 3, 4, 5])
let vc = v.copy()
inspect!(vc, content="@immut/array.of([1, 2, 3, 4, 5])")
inspect!(v == vc, content="true")
assert_false!(physical_equal(v, vc))
let v = @array.new()
let vc : @array.T[Int] = v.copy()
inspect!(vc, content="@immut/array.of([])")
inspect!(v == vc, content="true")
assert_false!(physical_equal(v, vc))
}

test "op_get" {
let v = @array.of([1, 2, 3, 4, 5])
inspect!(v[0], content="1")
Expand Down
15 changes: 1 addition & 14 deletions immut/array/array_wbtest.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test "mix" {
v,
content="@immut/array.of([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])",
)
let mut v2 = v.copy()
let mut v2 = v
for i = 0; i < 100; i = i + 1 {
v2 = v2.set(i, i * 2)
}
Expand Down Expand Up @@ -88,19 +88,6 @@ test "op_get" {
inspect!(v[bf / 2], content=v_content[bf / 2].to_string())
}

test "copy" {
let bf = branching_factor_power(4)
let v1_content = random_array(bf / 2)
let v2_content = random_array(bf / 3)
let v_content = v1_content + v2_content
let v1 = from_iter(v1_content.iter())
let v2 = from_iter(v2_content.iter())
let v = v1.concat(v2)
let v_copy = v.copy()
check_array_eq!(v_content, v_copy)
check_array_eq!(v_content, v)
}

test "concat-two-full-tree" {
let bf = branching_factor_power(4)
execute_array_test!(gen_concat_seq_from_len_array([bf, bf]))
Expand Down

0 comments on commit c6abd24

Please sign in to comment.