Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#### :boom: Breaking Change

- Remove runtime APIs that were deprecated for removal in ReScript 13, including the `Char` module, unsafe `Obj` operations, legacy `Pervasives` helpers, and `Array.unsafe_get`. https://github.com/rescript-lang/rescript/pull/8564
- Remove the deprecated `Js` namespace and its runtime modules. https://github.com/rescript-lang/rescript/pull/8531
- Move Belt into the separately installed `@rescript/belt` package. Projects using Belt must install the package and list it in their `rescript.json` dependencies. https://github.com/rescript-lang/rescript/pull/8554

Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/belt/src/Belt_Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ one by one using `f(xi, yi)`; and return true if all results are true false othe
## Examples

```rescript
Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true
Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => Math.Int.abs(a) == Math.Int.abs(b)) == true
```
*/
let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool
Expand Down
12 changes: 6 additions & 6 deletions packages/@rescript/belt/src/Belt_HashMap.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let rec copyBucketReHash = (~hash, ~h_buckets, ~ndata_tail, old_bucket) =>
switch C.toOpt(old_bucket) {
| None => ()
| Some(cell) =>
let nidx = land(hash(cell.N.key), A.length(h_buckets) - 1)
let nidx = Int.bitwiseAnd(hash(cell.N.key), A.length(h_buckets) - 1)
let v = C.return(cell)
switch C.toOpt(A.getUnsafe(ndata_tail, nidx)) {
| None => A.setUnsafe(h_buckets, nidx, v)
Expand Down Expand Up @@ -75,7 +75,7 @@ let rec replaceInBucket = (~eq, key, info, cell) =>
let set0 = (h, key, value, ~eq, ~hash) => {
let h_buckets = h.C.buckets
let buckets_len = A.length(h_buckets)
let i = land(hash(key), buckets_len - 1)
let i = Int.bitwiseAnd(hash(key), buckets_len - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None =>
Expand All @@ -87,7 +87,7 @@ let set0 = (h, key, value, ~eq, ~hash) => {
h.C.size = h.C.size + 1
}
}
if h.C.size > lsl(buckets_len, 1) {
if h.C.size > Int.shiftLeft(buckets_len, 1) {
resize(~hash, h)
}
}
Expand All @@ -113,7 +113,7 @@ let rec removeInBucket = (h, h_buckets, i, key, prec, bucket, ~eq) =>

let remove = (h, key) => {
let h_buckets = h.C.buckets
let i = land(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let i = Int.bitwiseAnd(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, i)
switch C.toOpt(bucket) {
| None => ()
Expand Down Expand Up @@ -141,7 +141,7 @@ let rec getAux = (~eq, key, buckets) =>

let get = (h, key) => {
let h_buckets = h.C.buckets
let nid = land(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
switch C.toOpt(A.getUnsafe(h_buckets, nid)) {
| None => None
| Some(cell1: N.bucket<_>) =>
Expand Down Expand Up @@ -179,7 +179,7 @@ let rec memInBucket = (key, cell, ~eq) =>

let has = (h, key) => {
let h_buckets = h.C.buckets
let nid = land(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, nid)
switch C.toOpt(bucket) {
| None => false
Expand Down
12 changes: 6 additions & 6 deletions packages/@rescript/belt/src/Belt_HashMapInt.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let rec copyBucketReHash = (~h_buckets, ~ndata_tail, old_bucket: C.opt<N.bucket<
switch C.toOpt(old_bucket) {
| None => ()
| Some(cell) =>
let nidx = land(hash(cell.key), A.length(h_buckets) - 1)
let nidx = Int.bitwiseAnd(hash(cell.key), A.length(h_buckets) - 1)
let v = C.return(cell)
switch C.toOpt(A.getUnsafe(ndata_tail, nidx)) {
| None => A.setUnsafe(h_buckets, nidx, v)
Expand Down Expand Up @@ -67,7 +67,7 @@ let rec replaceInBucket = (key: key, info, cell) =>
let set = (h, key: key, value) => {
let h_buckets = h.C.buckets
let buckets_len = A.length(h_buckets)
let i = land(hash(key), buckets_len - 1)
let i = Int.bitwiseAnd(hash(key), buckets_len - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None =>
Expand All @@ -79,7 +79,7 @@ let set = (h, key: key, value) => {
h.C.size = h.C.size + 1
}
}
if h.C.size > lsl(buckets_len, 1) {
if h.C.size > Int.shiftLeft(buckets_len, 1) {
resize(h)
}
}
Expand All @@ -99,7 +99,7 @@ let rec removeInBucket = (h, h_buckets, i, key: key, prec, buckets) =>

let remove = (h, key) => {
let h_buckets = h.C.buckets
let i = land(hash(key), A.length(h_buckets) - 1)
let i = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, i)
switch C.toOpt(bucket) {
| None => ()
Expand All @@ -126,7 +126,7 @@ let rec getAux = (key: key, buckets) =>

let get = (h, key: key) => {
let h_buckets = h.C.buckets
let nid = land(hash(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
switch C.toOpt(A.getUnsafe(h_buckets, nid)) {
| None => None
| Some(cell1) =>
Expand Down Expand Up @@ -163,7 +163,7 @@ let rec memInBucket = (key: key, cell) =>

let has = (h, key) => {
let h_buckets = h.C.buckets
let nid = land(hash(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, nid)
switch C.toOpt(bucket) {
| None => false
Expand Down
12 changes: 6 additions & 6 deletions packages/@rescript/belt/src/Belt_HashMapString.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let rec copyBucketReHash = (~h_buckets, ~ndata_tail, old_bucket: C.opt<N.bucket<
switch C.toOpt(old_bucket) {
| None => ()
| Some(cell) =>
let nidx = land(hash(cell.key), A.length(h_buckets) - 1)
let nidx = Int.bitwiseAnd(hash(cell.key), A.length(h_buckets) - 1)
let v = C.return(cell)
switch C.toOpt(A.getUnsafe(ndata_tail, nidx)) {
| None => A.setUnsafe(h_buckets, nidx, v)
Expand Down Expand Up @@ -67,7 +67,7 @@ let rec replaceInBucket = (key: key, info, cell) =>
let set = (h, key: key, value) => {
let h_buckets = h.C.buckets
let buckets_len = A.length(h_buckets)
let i = land(hash(key), buckets_len - 1)
let i = Int.bitwiseAnd(hash(key), buckets_len - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None =>
Expand All @@ -79,7 +79,7 @@ let set = (h, key: key, value) => {
h.C.size = h.C.size + 1
}
}
if h.C.size > lsl(buckets_len, 1) {
if h.C.size > Int.shiftLeft(buckets_len, 1) {
resize(h)
}
}
Expand All @@ -99,7 +99,7 @@ let rec removeInBucket = (h, h_buckets, i, key: key, prec, buckets) =>

let remove = (h, key) => {
let h_buckets = h.C.buckets
let i = land(hash(key), A.length(h_buckets) - 1)
let i = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, i)
switch C.toOpt(bucket) {
| None => ()
Expand All @@ -126,7 +126,7 @@ let rec getAux = (key: key, buckets) =>

let get = (h, key: key) => {
let h_buckets = h.C.buckets
let nid = land(hash(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
switch C.toOpt(A.getUnsafe(h_buckets, nid)) {
| None => None
| Some(cell1) =>
Expand Down Expand Up @@ -163,7 +163,7 @@ let rec memInBucket = (key: key, cell) =>

let has = (h, key) => {
let h_buckets = h.C.buckets
let nid = land(hash(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, nid)
switch C.toOpt(bucket) {
| None => false
Expand Down
13 changes: 8 additions & 5 deletions packages/@rescript/belt/src/Belt_HashSet.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ let rec copyBucket = (~hash, ~h_buckets, ~ndata_tail, old_bucket) =>
switch C.toOpt(old_bucket) {
| None => ()
| Some(cell) =>
let nidx = land(Belt_Id.getHashInternal(hash)(cell.N.key), A.length(h_buckets) - 1)
let nidx = Stdlib.Int.bitwiseAnd(
Belt_Id.getHashInternal(hash)(cell.N.key),
A.length(h_buckets) - 1,
)
let v = C.return(cell)
switch C.toOpt(A.getUnsafe(ndata_tail, nidx)) {
| None => A.setUnsafe(h_buckets, nidx, v)
Expand Down Expand Up @@ -69,7 +72,7 @@ let rec removeBucket = (~eq, h, h_buckets, i, key, prec, cell) => {
let remove = (h, key) => {
let eq = h.C.eq
let h_buckets = h.C.buckets
let i = land(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let i = Stdlib.Int.bitwiseAnd(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None => ()
Expand Down Expand Up @@ -101,15 +104,15 @@ let rec addBucket = (h, key, cell, ~eq) =>
let add0 = (h, key, ~hash, ~eq) => {
let h_buckets = h.C.buckets
let buckets_len = A.length(h_buckets)
let i = land(Belt_Id.getHashInternal(hash)(key), buckets_len - 1)
let i = Stdlib.Int.bitwiseAnd(Belt_Id.getHashInternal(hash)(key), buckets_len - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None =>
h.C.size = h.C.size + 1
A.setUnsafe(h_buckets, i, C.return({N.key, next: C.emptyOpt}))
| Some(cell) => addBucket(~eq, h, key, cell)
}
if h.C.size > lsl(buckets_len, 1) {
if h.C.size > Stdlib.Int.shiftLeft(buckets_len, 1) {
tryDoubleResize(~hash, h)
}
}
Expand All @@ -125,7 +128,7 @@ let rec memInBucket = (~eq, key, cell) =>

let has = (h, key) => {
let (eq, h_buckets) = (h.C.eq, h.C.buckets)
let nid = land(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let nid = Stdlib.Int.bitwiseAnd(Belt_Id.getHashInternal(h.C.hash)(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, nid)
switch C.toOpt(bucket) {
| None => false
Expand Down
4 changes: 2 additions & 2 deletions packages/@rescript/belt/src/Belt_HashSet.resi
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ different _hash_ functions will have different type.
## Examples

```rescript
module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b))
module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => Int.bitwiseAnd(a, 65535), ~eq=(a, b) => a == b))

let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40)

module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b))
module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => Int.bitwiseAnd(a, 255), ~eq=(a, b) => a == b))

let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40)

Expand Down
10 changes: 5 additions & 5 deletions packages/@rescript/belt/src/Belt_HashSetInt.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let rec copyBucket = (~h_buckets, ~ndata_tail, old_bucket) =>
switch C.toOpt(old_bucket) {
| None => ()
| Some(cell) =>
let nidx = land(hash(cell.N.key), A.length(h_buckets) - 1)
let nidx = Int.bitwiseAnd(hash(cell.N.key), A.length(h_buckets) - 1)
let v = C.return(cell)
switch C.toOpt(A.getUnsafe(ndata_tail, nidx)) {
| None => A.setUnsafe(h_buckets, nidx, v)
Expand Down Expand Up @@ -60,7 +60,7 @@ let rec removeBucket = (h, h_buckets, i, key: key, prec, cell) => {

let remove = (h, key: key) => {
let h_buckets = h.C.buckets
let i = land(hash(key), A.length(h_buckets) - 1)
let i = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None => ()
Expand Down Expand Up @@ -92,15 +92,15 @@ let rec addBucket = (h, key: key, cell) =>
let add = (h, key: key) => {
let h_buckets = h.C.buckets
let buckets_len = A.length(h_buckets)
let i = land(hash(key), buckets_len - 1)
let i = Int.bitwiseAnd(hash(key), buckets_len - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None =>
A.setUnsafe(h_buckets, i, C.return({N.key, next: C.emptyOpt}))
h.C.size = h.C.size + 1
| Some(cell) => addBucket(h, key, cell)
}
if h.C.size > lsl(buckets_len, 1) {
if h.C.size > Int.shiftLeft(buckets_len, 1) {
tryDoubleResize(h)
}
}
Expand All @@ -114,7 +114,7 @@ let rec memInBucket = (key: key, cell) =>

let has = (h, key) => {
let h_buckets = h.C.buckets
let nid = land(hash(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, nid)
switch C.toOpt(bucket) {
| None => false
Expand Down
10 changes: 5 additions & 5 deletions packages/@rescript/belt/src/Belt_HashSetString.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let rec copyBucket = (~h_buckets, ~ndata_tail, old_bucket) =>
switch C.toOpt(old_bucket) {
| None => ()
| Some(cell) =>
let nidx = land(hash(cell.N.key), A.length(h_buckets) - 1)
let nidx = Int.bitwiseAnd(hash(cell.N.key), A.length(h_buckets) - 1)
let v = C.return(cell)
switch C.toOpt(A.getUnsafe(ndata_tail, nidx)) {
| None => A.setUnsafe(h_buckets, nidx, v)
Expand Down Expand Up @@ -60,7 +60,7 @@ let rec removeBucket = (h, h_buckets, i, key: key, prec, cell) => {

let remove = (h, key: key) => {
let h_buckets = h.C.buckets
let i = land(hash(key), A.length(h_buckets) - 1)
let i = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None => ()
Expand Down Expand Up @@ -92,15 +92,15 @@ let rec addBucket = (h, key: key, cell) =>
let add = (h, key: key) => {
let h_buckets = h.C.buckets
let buckets_len = A.length(h_buckets)
let i = land(hash(key), buckets_len - 1)
let i = Int.bitwiseAnd(hash(key), buckets_len - 1)
let l = A.getUnsafe(h_buckets, i)
switch C.toOpt(l) {
| None =>
A.setUnsafe(h_buckets, i, C.return({N.key, next: C.emptyOpt}))
h.C.size = h.C.size + 1
| Some(cell) => addBucket(h, key, cell)
}
if h.C.size > lsl(buckets_len, 1) {
if h.C.size > Int.shiftLeft(buckets_len, 1) {
tryDoubleResize(h)
}
}
Expand All @@ -114,7 +114,7 @@ let rec memInBucket = (key: key, cell) =>

let has = (h, key) => {
let h_buckets = h.C.buckets
let nid = land(hash(key), A.length(h_buckets) - 1)
let nid = Int.bitwiseAnd(hash(key), A.length(h_buckets) - 1)
let bucket = A.getUnsafe(h_buckets, nid)
switch C.toOpt(bucket) {
| None => false
Expand Down
4 changes: 2 additions & 2 deletions packages/@rescript/belt/src/Belt_List.resi
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) == false

Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) == true

Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) == true
Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => Math.Int.abs(a) == Math.Int.abs(b)) == true
```
*/
let eq: (t<'a>, t<'a>, ('a, 'a) => bool) => bool
Expand All @@ -780,7 +780,7 @@ list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) == true

list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) == false

list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) == true
list{-1, -2, -3}->Belt.List.has(2, (a, b) => Math.Int.abs(a) == Math.Int.abs(b)) == true
```
*/
let has: (t<'a>, 'b, ('a, 'b) => bool) => bool
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/belt/src/Belt_Result.resi
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ordinary value.
## Examples

```rescript
let f = x => sqrt(Belt.Int.toFloat(x))
let f = x => Math.sqrt(Belt.Int.toFloat(x))

Belt.Result.map(Ok(64), f) == Ok(8.0)

Expand Down
6 changes: 3 additions & 3 deletions packages/@rescript/belt/src/Belt_SortArray.resi
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ element that is larger than value.
If value is not found and value is greater
than all elements in array, the negative number returned is the bitwise
complement of (the index of the last element plus 1)for example, if `key` is
smaller than all elements return `-1` since `lnot(-1) == 0` if `key` is larger
than all elements return `lnot(-1) == 0` since `lnot(- (len + 1)) == len`
smaller than all elements return `-1` since `Int.bitwiseNot(-1) == 0` if `key` is larger
than all elements return `Int.bitwiseNot(-1) == 0` since `Int.bitwiseNot(- (len + 1)) == len`

## Examples

```rescript
Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4

lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2
Int.bitwiseNot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2
```
*/
let binarySearchBy: (array<'a>, 'a, ('a, 'a) => int) => int
Expand Down
Loading
Loading