Skip to content

Commit

Permalink
hongbo/get rid of T (#552)
Browse files Browse the repository at this point in the history
* remove usage of Array::

* tweak

* add missing APIs for hashset

* fmt
  • Loading branch information
bobzhang committed Jun 13, 2024
1 parent e795643 commit 84eda7a
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 90 deletions.
6 changes: 3 additions & 3 deletions array/array_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test "op_equal" {
}

test "pop" {
let v = Array::new()
let v = []
v.push(3)
v.push(4)
@assertion.assert_eq(v.length(), 2)?
Expand All @@ -60,7 +60,7 @@ test "pop" {
}

test "pop_exn" {
let v = Array::new()
let v = []
v.push(3)
v.push(4)
@assertion.assert_eq(v.length(), 2)?
Expand Down Expand Up @@ -175,7 +175,7 @@ test "filter" {
}

test "is_empty" {
let v = Array::new()
let v = []
@assertion.assert_true(v.is_empty())?
v.push(3)
@assertion.assert_false(v.is_empty())?
Expand Down
2 changes: 1 addition & 1 deletion array/fixedarray.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub fn FixedArray::from_array[T](array : Array[T]) -> FixedArray[T] {
}

test "from_array" {
let array = FixedArray::[1, 2, 3, 4, 5]
let array : FixedArray[_] = [1, 2, 3, 4, 5]
@assertion.assert_eq(array, [1, 2, 3, 4, 5])?
}

Expand Down
2 changes: 1 addition & 1 deletion array/fixedarray_sort.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn timsort[T : Compare](arr : FixedArraySlice[T]) -> Unit {
}
let mut end = 0
let mut start = 0
let runs : Array[TimSortRun] = Array::new()
let runs : Array[TimSortRun] = []
while end < len {
let (streak_end, was_reversed) = find_streak(arr.slice(start, arr.end))
end += streak_end
Expand Down
4 changes: 2 additions & 2 deletions array/sort.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
/// # Example
///
/// ```
/// let arr = Array::[5, 4, 3, 2, 1]
/// let arr = [5, 4, 3, 2, 1]
/// arr.sort()
/// debug(arr) //output: Array::[1, 2, 3, 4, 5]
/// debug(arr) //output: [1, 2, 3, 4, 5]
/// ```
pub fn sort[T : Compare](self : Array[T]) -> Unit {
quick_sort(
Expand Down
8 changes: 4 additions & 4 deletions array/sort_by.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
/// # Example
///
/// ```
/// let arr = Array::[5, 3, 2, 4, 1]
/// let arr = [5, 3, 2, 4, 1]
/// arr.sort_by_key(fn (x) {-x})
/// debug(arr) //output: Array::[5, 4, 3, 2, 1]
/// debug(arr) //output: [5, 4, 3, 2, 1]
/// ```
pub fn sort_by_key[T, K : Compare](self : Array[T], map : (T) -> K) -> Unit {
quick_sort_by(
Expand All @@ -39,9 +39,9 @@ pub fn sort_by_key[T, K : Compare](self : Array[T], map : (T) -> K) -> Unit {
/// # Example
///
/// ```
/// let arr = Array::[5, 3, 2, 4, 1]
/// let arr = [5, 3, 2, 4, 1]
/// arr.sort_by(fn (a, b) { a - b })
/// debug(arr) //output: Array::[1, 2, 3, 4, 5]
/// debug(arr) //output: [1, 2, 3, 4, 5]
/// ```
pub fn sort_by[T](self : Array[T], cmp : (T, T) -> Int) -> Unit {
quick_sort_by(
Expand Down

0 comments on commit 84eda7a

Please sign in to comment.