Skip to content

Commit 893bde4

Browse files
authored
fix: always use u32 to index arrays (#6)
1 parent 57ecfa6 commit 893bde4

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/lib.nr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
unconstrained fn __get_shuffle_indices<T, let N: u32>(lhs: [T; N], rhs: [T; N]) -> [Field; N]
1+
unconstrained fn __get_shuffle_indices<T, let N: u32>(lhs: [T; N], rhs: [T; N]) -> [u32; N]
22
where
33
T: std::cmp::Eq,
44
{
5-
let mut shuffle_indices: [Field; N] = [0; N];
5+
let mut shuffle_indices: [u32; N] = [0; N];
66

77
let mut shuffle_mask: [bool; N] = [false; N];
88
for i in 0..N {
@@ -11,7 +11,7 @@ where
1111
if ((shuffle_mask[j] == false) & (!found)) {
1212
if (lhs[i] == rhs[j]) {
1313
found = true;
14-
shuffle_indices[i] = j as Field;
14+
shuffle_indices[i] = j;
1515
shuffle_mask[j] = true;
1616
}
1717
}
@@ -25,11 +25,11 @@ where
2525
shuffle_indices
2626
}
2727

28-
unconstrained fn __get_index<let N: u32>(indices: [Field; N], idx: Field) -> Field {
28+
unconstrained fn __get_index<let N: u32>(indices: [u32; N], idx: u32) -> u32 {
2929
let mut result = 0;
3030
for i in 0..N {
3131
if (indices[i] == idx) {
32-
result = i as Field;
32+
result = i;
3333
break;
3434
}
3535
}
@@ -44,9 +44,9 @@ where
4444
let shuffle_indices = unsafe { __get_shuffle_indices(lhs, rhs) };
4545

4646
for i in 0..N {
47-
let idx = unsafe { __get_index(shuffle_indices, i as Field) };
47+
let idx = unsafe { __get_index(shuffle_indices, i) };
4848
// checks the relation between shuffle_indices and output of __get_index
49-
assert_eq(shuffle_indices[idx], i as Field);
49+
assert_eq(shuffle_indices[idx], i);
5050
}
5151
for i in 0..N {
5252
let idx = shuffle_indices[i];
@@ -57,15 +57,15 @@ where
5757
}
5858
}
5959

60-
pub fn get_shuffle_indices<T, let N: u32>(lhs: [T; N], rhs: [T; N]) -> [Field; N]
60+
pub fn get_shuffle_indices<T, let N: u32>(lhs: [T; N], rhs: [T; N]) -> [u32; N]
6161
where
6262
T: std::cmp::Eq,
6363
{
6464
//@Safety: as explained in check_shuffle function
6565
let shuffle_indices = unsafe { __get_shuffle_indices(lhs, rhs) };
6666
for i in 0..N {
67-
let idx = unsafe { __get_index(shuffle_indices, i as Field) };
68-
assert_eq(shuffle_indices[idx], i as Field);
67+
let idx = unsafe { __get_index(shuffle_indices, i) };
68+
assert_eq(shuffle_indices[idx], i);
6969
}
7070
for i in 0..N {
7171
let idx = shuffle_indices[i];

0 commit comments

Comments
 (0)