pub fn send_random_queries(
	channel_idx: usize, count: usize, mask: Uint256, queries_out_idx: usize, stride: usize, ctx: &mut Vec<Uint256>
) -> Uint256 {

	let mut shift = 0;
	let mut end_idx = queries_out_idx;
	let mut val = uint256_ops::get_uint256("0");

	for _ in 0..count {
		if shift == 0 {
			val = get_random_bytes( get_prng_ptr(channel_idx), ctx );
			shift = 8;
		}
		
		shift -= 2;
		let r_shift = val.clone() / prime_field::fpow( &uint256_ops::get_uint256("2"), &uint256_ops::from_usize(shift) ); // val >> shift
		let query_idx = uint256_ops::bitwise_and( &mask, &r_shift );
		
		// Insert new query_idx in the correct place like insertion sort.
		let mut idx_cpy = end_idx;
		let mut curr = uint256_ops::get_uint256("0");
		while idx_cpy > queries_out_idx {
			curr = ctx[idx_cpy - stride].clone();

			if query_idx >= curr {
				break;
			}

			ctx[idx_cpy] = curr.clone();
			idx_cpy -= stride;
		}

		if query_idx != curr {
			ctx[idx_cpy] = uint256_ops::make_copy( &query_idx );
			end_idx += stride;
		} else {
			// Revert right shuffling.
			while idx_cpy < end_idx {
				ctx[idx_cpy] = uint256_ops::make_copy( &ctx[idx_cpy + stride] );
				idx_cpy += stride;
			}
		}

	}

	return uint256_ops::from_usize( (end_idx - queries_out_idx) / stride );

}
/*
	Sends random queries and returns an array of queries sorted in ascending order.
	Generates count queries in the range [0, mask] and returns the number of unique queries.
	Note that mask is of the form 2^k-1 (for some k).
	Note that queriesOutPtr may be (and is) inteleaved with other arrays. The stride parameter
	is passed to indicate the distance between every two entries to the queries array, i.e.
	stride = 0x20*(number of interleaved arrays).
*/
Sends random queries and returns an array of queries sorted in ascending order.
Generates count queries in the range [0, mask] and returns the number of unique queries.
Note that mask is of the form 2^k-1 (for some k).
Note that queriesOutPtr may be (and is) inteleaved with other arrays. The stride parameter
is passed to indicate the distance between every two entries to the queries array, i.e.
stride = 0x20*(number of interleaved arrays).
Sends random queries and returns an array of queries sorted in ascending order . Generates count queries in the range [ 0 mask ] and returns the number of unique queries . Note that mask is of the form 2^k - 1 ( for some k ) . Note that queriesOutPtr may be ( and is ) inteleaved with other arrays . The stride parameter is passed to indicate the distance between every two entries to the queries array i . e . stride = 0x20 * ( number of interleaved arrays ) .
pub fn send_random_queries(
	channel_idx: usize, count: usize, mask: Uint256, queries_out_idx: usize, stride: usize, ctx: &mut Vec<Uint256>
) -> Uint256 {
	let mut shift = 0;
	let mut end_idx = queries_out_idx;
	let mut val = uint256_ops::get_uint256("0");
	for _ in 0..count {
		if shift == 0 {
			val = get_random_bytes( get_prng_ptr(channel_idx), ctx );
			shift = 8;
		}
		shift -= 2;
		let r_shift = val.clone() / prime_field::fpow( &uint256_ops::get_uint256("2"), &uint256_ops::from_usize(shift) ); // val >> shift
		let query_idx = uint256_ops::bitwise_and( &mask, &r_shift );
		// Insert new query_idx in the correct place like insertion sort.
		let mut idx_cpy = end_idx;
		let mut curr = uint256_ops::get_uint256("0");
		while idx_cpy > queries_out_idx {
			curr = ctx[idx_cpy - stride].clone();
			if query_idx >= curr {
				break;
			}
			ctx[idx_cpy] = curr.clone();
			idx_cpy -= stride;
		}
		if query_idx != curr {
			ctx[idx_cpy] = uint256_ops::make_copy( &query_idx );
			end_idx += stride;
		} else {
			// Revert right shuffling.
			while idx_cpy < end_idx {
				ctx[idx_cpy] = uint256_ops::make_copy( &ctx[idx_cpy + stride] );
				idx_cpy += stride;
			}
		}
	}
	return uint256_ops::from_usize( (end_idx - queries_out_idx) / stride );
}
pub fn send_random_queries ( channel_idx : usize , count : usize , mask : Uint256 , queries_out_idx : usize , stride : usize , ctx : & mut Vec < Uint256 > ) -> Uint256 { let mut shift = 0 ; let mut end_idx = queries_out_idx ; let mut val = uint256_ops :: get_uint256 ( " " ) ; for _ in 0 .. count { if shift == 0 { val = get_random_bytes ( get_prng_ptr ( channel_idx ) , ctx ) ; shift = 8 ; } shift -= 2 ; let r_shift = val . clone ( ) / prime_field :: fpow ( & uint256_ops :: get_uint256 ( " " ) , & uint256_ops :: from_usize ( shift ) ) ; // val >> shift let query_idx = uint256_ops :: bitwise_and ( & mask , & r_shift ) ; // Insert new query_idx in the correct place like insertion sort. let mut idx_cpy = end_idx ; let mut curr = uint256_ops :: get_uint256 ( " " ) ; while idx_cpy > queries_out_idx { curr = ctx [ idx_cpy - stride ] . clone ( ) ; if query_idx >= curr { break ; } ctx [ idx_cpy ] = curr . clone ( ) ; idx_cpy -= stride ; } if query_idx != curr { ctx [ idx_cpy ] = uint256_ops :: make_copy ( & query_idx ) ; end_idx += stride ; } else { // Revert right shuffling. while idx_cpy < end_idx { ctx [ idx_cpy ] = uint256_ops :: make_copy ( & ctx [ idx_cpy + stride ] ) ; idx_cpy += stride ; } } } return uint256_ops :: from_usize ( ( end_idx - queries_out_idx ) / stride ) ; }
Sends random queries and returns an array of queries sorted in ascending order.
Sends random queries and returns an array of queries sorted in ascending order .
channel_idx
usize
count
usize
mask
Uint256
queries_out_idx
usize
stride
usize
ctx
&mut Vec<Uint256>
channel_idx
usize
count
usize
mask
Uint256
queries_out_idx
usize
stride
usize
ctx
&mut Vec<Uint256>