Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Feb 27, 2024
1 parent 438d190 commit c82a9c9
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 286 deletions.
27 changes: 13 additions & 14 deletions noir_stdlib/src/array.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,41 @@ impl<T, N> [T; N] {
for i in 0..N {
let pos = find_index(sorted_index, i);
assert(sorted_index[pos] == i);
}
}
// Sort the array using the indexes
for i in 0..N {
for i in 0..N {
result[i] = self[sorted_index[i]];
}
}
// Ensure the array is sorted
for i in 0..N-1 {
assert(ordering(result[i], result[i+1]));
for i in 0..N - 1 {
assert(ordering(result[i], result[i + 1]));
}

result
}

/// Returns the index of the elements in the array that would sort it, using the provided custom sorting function.
unconstrained fn get_sorting_index<Env>(self, ordering: fn[Env](T, T) -> bool) -> [Field; N] {
let mut result = [0;N];
let mut result = [0; N];
let mut a = self;
for i in 0..N {
result[i] = i;
}
for i in 1 .. N {
for i in 1..N {
for j in 0..i {
if ordering(a[i], a[j]) {
let old_a_j = a[j];
a[j] = a[i];
a[i] = old_a_j;
let old_j = result[j];
result[j] = result[i];
result[i] = old_j;
result[i] = old_j;
}
}
}
result
}


// Converts an array into a slice.
pub fn as_slice(self) -> [T] {
let mut slice = [];
Expand All @@ -68,7 +67,7 @@ impl<T, N> [T; N] {
let first_elem = f(self[0]);
let mut ret = [first_elem; N];

for i in 1 .. self.len() {
for i in 1..self.len() {
ret[i] = f(self[i]);
}

Expand All @@ -90,7 +89,7 @@ impl<T, N> [T; N] {
// element of the given array as its starting accumulator value.
pub fn reduce<Env>(self, f: fn[Env](T, T) -> T) -> T {
let mut accumulator = self[0];
for i in 1 .. self.len() {
for i in 1..self.len() {
accumulator = f(accumulator, self[i]);
}
accumulator
Expand All @@ -117,12 +116,12 @@ impl<T, N> [T; N] {

// helper function used to look up the position of a value in an array of Field
// Note that function returns 0 if the value is not found
unconstrained fn find_index<N>(a: [Field;N], find: Field) -> Field {
unconstrained fn find_index<N>(a: [Field; N], find: Field) -> Field {
let mut result = 0;
for i in 0..a.len() {
if a[i] == find {
result = i;
}
}
}
result
}
}
16 changes: 5 additions & 11 deletions noir_stdlib/src/bigint.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ global secpr1_fq = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF];
global secpr1_fr = [0x51, 0x25, 0x63, 0xFC, 0xC2, 0xCA, 0xB9, 0xF3, 0x84, 0x9E, 0x17, 0xA7, 0xAD, 0xFA, 0xE6, 0xBC,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,0xFF, 0xFF, 0xFF, 0xFF];


struct BigInt {
pointer: u32,
Expand All @@ -22,17 +21,13 @@ struct BigInt {

impl BigInt {
#[builtin(bigint_add)]
fn bigint_add(self, other: BigInt) -> BigInt {
}
fn bigint_add(self, other: BigInt) -> BigInt {}
#[builtin(bigint_sub)]
fn bigint_sub(self, other: BigInt) -> BigInt {
}
fn bigint_sub(self, other: BigInt) -> BigInt {}
#[builtin(bigint_mul)]
fn bigint_mul(self, other: BigInt) -> BigInt {
}
fn bigint_mul(self, other: BigInt) -> BigInt {}
#[builtin(bigint_div)]
fn bigint_div(self, other: BigInt) -> BigInt {
}
fn bigint_div(self, other: BigInt) -> BigInt {}
#[builtin(bigint_from_le_bytes)]
fn from_le_bytes(bytes: [u8], modulus: [u8]) -> BigInt {}
#[builtin(bigint_to_le_bytes)]
Expand All @@ -42,14 +37,13 @@ impl BigInt {
let bytes = self.to_le_bytes();
let o_bytes = other.to_le_bytes();
let mut result = true;
for i in 0..32{
for i in 0..32 {
result = result & (bytes[i] == o_bytes[i]);
}
result
}
}


trait BigField {
fn from_le_bytes(bytes: [u8]) -> Self;
fn to_le_bytes(self) -> [u8];
Expand Down
2 changes: 1 addition & 1 deletion noir_stdlib/src/collections/bounded_vec.nr
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ impl<T, MaxLen> BoundedVec<T, MaxLen> {
}
ret
}
}
}
8 changes: 4 additions & 4 deletions noir_stdlib/src/collections/vec.nr
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ impl<T> Vec<T> {
/// points beyond the end of the vector.
pub fn get(self, index: Field) -> T {
self.slice[index]
}
}

/// Push a new element to the end of the vector, returning a
/// new vector with a length one greater than the
/// original unmodified vector.
pub fn push(&mut self, elem: T) {
pub fn push(&mut self, elem: T) {
self.slice = self.slice.push_back(elem);
}

/// Pop an element from the end of the given vector, returning
/// a new vector with a length of one less than the given vector,
/// as well as the popped element.
/// Panics if the given vector's length is zero.
pub fn pop(&mut self) -> T {
pub fn pop(&mut self) -> T {
let (popped_slice, last_elem) = self.slice.pop_back();
self.slice = popped_slice;
last_elem
Expand All @@ -42,7 +42,7 @@ impl<T> Vec<T> {
/// after it to the right
pub fn insert(&mut self, index: Field, elem: T) {
self.slice = self.slice.insert(index, elem);
}
}

/// Remove an element at a specified index, shifting all elements
/// after it to the left, returning the removed element
Expand Down
Loading

0 comments on commit c82a9c9

Please sign in to comment.