Skip to content

Commit 484afad

Browse files
authored
chore: refactor key_exists_impl_var (#87)
1 parent 33bf554 commit 484afad

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/getters.nr

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,27 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
193193
}
194194

195195
let found = search_result.found as Field;
196-
let target_lt_smallest_entry = search_result.target_lt_smallest_entry as Field;
197-
let target_gt_largest_entry = search_result.target_gt_largest_entry as Field;
196+
let target_lt_smallest_entry = search_result.target_lt_smallest_entry;
197+
let target_gt_largest_entry = search_result.target_gt_largest_entry;
198198

199199
// only one of "found", "target_lt_smallest_entry", "target_gt_largest_entry" can be true
200-
let exclusion_test = found + target_gt_largest_entry + target_lt_smallest_entry;
201-
assert(exclusion_test * exclusion_test == exclusion_test);
202-
203-
let mut lhs = self.key_hashes[search_result.lhs_index];
204-
let mut rhs = self.key_hashes[search_result.rhs_index];
200+
let exclusion_test =
201+
found + (target_gt_largest_entry as Field) + (target_lt_smallest_entry as Field);
202+
exclusion_test.assert_max_bit_size::<1>();
205203

206204
// case where hash < self.key_hashes[0]
207205
// 0 < hash < hashes[0]
208-
lhs = lhs * (1 - target_lt_smallest_entry);
206+
let lhs = self.key_hashes[search_result.lhs_index];
207+
let mut lhs = if target_lt_smallest_entry { 0 } else { lhs };
209208

210209
// case where hash > self.key_hashes[last]
211210
// largest < x < -1
212-
rhs = rhs * (1 - target_gt_largest_entry) + target_gt_largest_entry * HASH_MAXIMUM;
211+
let rhs = self.key_hashes[search_result.rhs_index];
212+
let mut rhs = if target_gt_largest_entry {
213+
HASH_MAXIMUM
214+
} else {
215+
rhs
216+
};
213217

214218
// case where hash == self.key_hashes[found_index]
215219
lhs -= found;

0 commit comments

Comments
 (0)