Skip to content

Commit 9b7a52a

Browse files
committed
tweak
1 parent 1c4c20e commit 9b7a52a

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

immut/hashmap/HAMT.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn[K : Eq, V] Node::get_with_path(
7777
}
7878
(Branch(children), path) => {
7979
let idx = path.idx()
80-
if children[idx] is Some(child) {
80+
if children.get(idx) is Some(child) {
8181
continue (child, path.next())
8282
}
8383
None
@@ -140,7 +140,7 @@ fn[K : Eq, V] add_with_path(
140140
}
141141
Branch(children) => {
142142
let idx = path.idx()
143-
match children[idx] {
143+
match children.get(idx) {
144144
Some(child) => {
145145
let child = child.add_with_path(key, value, path.next())
146146
Branch(children.replace(idx, child))
@@ -322,7 +322,7 @@ fn[K : Eq, V] remove_with_path(
322322
}
323323
Branch(children) => {
324324
let idx = path.idx()
325-
match children[idx] {
325+
match children.get(idx) {
326326
None => Some(self)
327327
Some(child) => {
328328
let new_child = child.remove_with_path(key, path.next())

immut/hashset/HAMT.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn[A : Eq] Node::contains(self : Node[A], key : A, path : Path) -> Bool {
4646
(Flat(key1, path1), path) => path == path1 && key == key1
4747
(Branch(children), path) => {
4848
let idx = path.idx()
49-
if children[idx] is Some(child) {
49+
if children.get(idx) is Some(child) {
5050
continue (child, path.next())
5151
}
5252
false
@@ -93,7 +93,7 @@ fn[A : Eq] add_with_path(self : Node[A], key : A, path : Path) -> Node[A] {
9393
}
9494
Branch(children) => {
9595
let idx = path.idx()
96-
match children[idx] {
96+
match children.get(idx) {
9797
Some(child) => {
9898
let child = child.add_with_path(key, path.next())
9999
Branch(children.replace(idx, child))
@@ -147,7 +147,7 @@ fn[A : Eq] remove_with_path(self : Node[A], key : A, path : Path) -> Node[A]? {
147147
}
148148
Branch(children) => {
149149
let idx = path.idx()
150-
match children[idx] {
150+
match children.get(idx) {
151151
None => Some(self)
152152
Some(child) => {
153153
let new_child = child.remove_with_path(key, path.next())

immut/internal/sparse_array/README.mbt.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test "sparse array basics" {
1717
inspect(single.size(), content="1")
1818
1919
// Check if element exists
20-
match single[5] {
20+
match single.get(5) {
2121
Some(val) => inspect(val, content="value")
2222
None => inspect(false, content="true")
2323
}
@@ -49,7 +49,7 @@ test "sparse array operations" {
4949
inspect(removed.size(), content="1")
5050
5151
// Check final value
52-
match removed[3] {
52+
match removed.get(3) {
5353
Some(val) => inspect(val, content="150")
5454
None => inspect(false, content="true")
5555
}
@@ -73,7 +73,7 @@ test "bitset operations" {
7373
inspect(with_more.size(), content="3")
7474
7575
// Access elements by index
76-
match with_more[3] {
76+
match with_more.get(3) {
7777
Some(val) => inspect(val, content="test")
7878
None => inspect(false, content="true")
7979
}
@@ -120,7 +120,7 @@ test "sparse array transformations" {
120120
// Map values to new type
121121
let doubled = numbers.map(fn(x) { x * 2 })
122122
inspect(doubled.size(), content="2")
123-
match doubled[1] {
123+
match doubled.get(1) {
124124
Some(val) => inspect(val, content="20")
125125
None => inspect(false, content="true")
126126
}
@@ -148,7 +148,7 @@ test "sparse array combinations" {
148148
inspect(combined.size(), content="3")
149149
150150
// Check combined values
151-
match combined[3] {
151+
match combined.get(3) {
152152
Some(val) => inspect(val, content="cC") // Combined "c" + "C"
153153
None => inspect(false, content="true")
154154
}
@@ -168,13 +168,13 @@ test "advanced sparse operations" {
168168
inspect(extended.size(), content="4")
169169
170170
// Access specific elements
171-
match extended[10] {
171+
match extended.get(10) {
172172
Some(val) => inspect(val, content="100")
173173
None => inspect(false, content="true")
174174
}
175175
176176
// Check non-existent element
177-
match extended[7] {
177+
match extended.get(7) {
178178
Some(_) => inspect(false, content="true")
179179
None => inspect(true, content="true") // Should be None
180180
}

immut/internal/sparse_array/pkg.generated.mbti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ fn[X] SparseArray::add(Self[X], Int, X) -> Self[X]
3131
fn[X] SparseArray::difference(Self[X], Self[X], (X, X) -> X?) -> Self[X]?
3232
fn[X] SparseArray::each(Self[X], (X) -> Unit raise?) -> Unit raise?
3333
fn[X] SparseArray::filter(Self[X], (X) -> X? raise?) -> Self[X]? raise?
34+
fn[X] SparseArray::get(Self[X], Int) -> X?
3435
fn[X] SparseArray::intersection(Self[X], Self[X], (X, X) -> X? raise?) -> Self[X]? raise?
3536
fn[X, Y] SparseArray::map(Self[X], (X) -> Y raise?) -> Self[Y] raise?
36-
fn[X] SparseArray::op_get(Self[X], Int) -> X?
3737
fn[X] SparseArray::remove(Self[X], Int) -> Self[X]
3838
fn[X] SparseArray::replace(Self[X], Int, X) -> Self[X]
3939
fn[X] SparseArray::size(Self[X]) -> Int

immut/internal/sparse_array/sparse_array.mbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn[X] singleton(idx : Int, value : X) -> SparseArray[X] {
3232
}
3333

3434
///|
35-
pub fn[X] op_get(self : SparseArray[X], idx : Int) -> X? {
35+
pub fn[X] get(self : SparseArray[X], idx : Int) -> X? {
3636
if self.elem_info.has(idx) {
3737
Some(self.data[self.elem_info.index_of(idx)])
3838
} else {
@@ -115,10 +115,10 @@ pub fn[X] SparseArray::union(
115115
let data = FixedArray::make(union_elem_info.size(), self.data[0])
116116
for rest = union_elem_info, index = 0; rest != empty_bitset; {
117117
let idx = rest.first_idx()
118-
data[index] = match self[idx] {
118+
data[index] = match self.get(idx) {
119119
None => other.unsafe_get(idx)
120120
Some(value1) =>
121-
match other[idx] {
121+
match other.get(idx) {
122122
None => value1
123123
Some(value2) => f(value1, value2)
124124
}
@@ -180,7 +180,7 @@ pub fn[X] SparseArray::difference(
180180
for rest = self_elem_info, index = 0, elem_info = self_elem_info; rest !=
181181
empty_bitset; {
182182
let idx = rest.first_idx()
183-
match other[idx] {
183+
match other.get(idx) {
184184
None => {
185185
data[index] = self.unsafe_get(idx)
186186
continue rest.remove(idx), index + 1, elem_info

immut/internal/sparse_array/sparse_array_test.mbt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@
1515
///|
1616
test "SparseArray" {
1717
let arr0 = @sparse_array.singleton(1, 1)
18-
inspect([arr0[0], arr0[1], arr0[2]], content="[None, Some(1), None]")
18+
inspect(
19+
[arr0.get(0), arr0.get(1), arr0.get(2)],
20+
content="[None, Some(1), None]",
21+
)
1922
let arr1 = arr0.add(2, 2)
20-
inspect([arr1[0], arr1[1], arr1[2]], content="[None, Some(1), Some(2)]")
23+
inspect(
24+
[arr1.get(0), arr1.get(1), arr1.get(2)],
25+
content="[None, Some(1), Some(2)]",
26+
)
2127
let arr2 = arr1.add(0, 0)
22-
inspect([arr2[0], arr2[1], arr2[2]], content="[Some(0), Some(1), Some(2)]")
28+
inspect(
29+
[arr2.get(0), arr2.get(1), arr2.get(2)],
30+
content="[Some(0), Some(1), Some(2)]",
31+
)
2332
let arr3 = arr2.replace(1, 42)
24-
inspect([arr3[0], arr3[1], arr3[2]], content="[Some(0), Some(42), Some(2)]")
33+
inspect(
34+
[arr3.get(0), arr3.get(1), arr3.get(2)],
35+
content="[Some(0), Some(42), Some(2)]",
36+
)
2537
}
2638

2739
///|
@@ -34,7 +46,15 @@ test "SparseArray::union" {
3446
let arr2 = @sparse_array.singleton(1, 10).add(2, 2).add(4, 40).add(31, 31)
3547
let arr3 = arr1.union(arr2, (_x, y) => y)
3648
inspect(
37-
[arr3[0], arr3[1], arr3[2], arr3[3], arr3[4], arr3[5], arr3[31]],
49+
[
50+
arr3.get(0),
51+
arr3.get(1),
52+
arr3.get(2),
53+
arr3.get(3),
54+
arr3.get(4),
55+
arr3.get(5),
56+
arr3.get(31),
57+
],
3858
content="[Some(0), Some(10), Some(2), Some(3), Some(40), Some(5), Some(31)]",
3959
)
4060
}

0 commit comments

Comments
 (0)