Skip to main content

ArrayUtils

Fast operations on sorted uint32_t arrays. All input arrays MUST be sorted in ascending order. Output arrays are dynamically allocated - caller must free with delete[]. Example:

Public Static Methods


and_scalar

static
Fast intersection (AND) of two sorted arrays.

Parameters

  • A First sorted array
  • lenA Length of array A
  • B Second sorted array
  • lenB Length of array B
  • out Output array (allocated by function, caller must delete[])

Returns

Size of intersection (elements in out) Time complexity: O(lenA + lenB) Space complexity: O(min(lenA, lenB))

or_scalar

static
Fast union (OR) of two sorted arrays.

Returns

Size of union (elements in out) Time complexity: O(lenA + lenB) Space complexity: O(lenA + lenB)

exclude_scalar

static
Exclude elements (A - B): elements in A but not in B.

Parameters

  • src Source array
  • lenSrc Length of source
  • filter Elements to exclude
  • lenFilter Length of filter
  • out Output array (allocated by function)

Returns

Size of result Time complexity: O(lenSrc + lenFilter)

skip_index_to_id

static
Binary search with skip-ahead. Searches for ‘id’ in sorted array. If found, sets curr_index to that index. If not found, sets curr_index to the index of the next larger element.

Parameters

  • curr_index Current index (input/output)
  • array Sorted array to search
  • array_len Length of array
  • id Value to search for

Returns

true if id was found, false otherwise

arrays_equal

static
Check if arrays are equal.

is_sorted

static
Check if array is sorted.

intersect

static
Intersection of two vectors (returns new vector)

union_of

static
Union of two vectors (returns new vector)

exclude

static
Exclude elements (a - b) (returns new vector)

contains

static
Check if element exists in sorted array.

contains

static