MCPcopy Create free account
hub / github.com/TanStack/db / arrayIncludesWithSet

Function arrayIncludesWithSet

packages/db/src/query/predicate-utils.ts:1142–1160  ·  view source on GitHub ↗

* Check if a value is in an array, with optional pre-built Set for optimization. * The primitiveSet is cached in InField during extraction and reused for all lookups.

(
  array: Array<any>,
  value: any,
  primitiveSet: Set<any> | null,
  arrayIsAllPrimitives?: boolean,
)

Source from the content-addressed store, hash-verified

1140 * The primitiveSet is cached in InField during extraction and reused for all lookups.
1141 */
1142function arrayIncludesWithSet(
1143 array: Array<any>,
1144 value: any,
1145 primitiveSet: Set<any> | null,
1146 arrayIsAllPrimitives?: boolean,
1147): boolean {
1148 // Fast path: use pre-built Set for O(1) lookup
1149 if (primitiveSet) {
1150 // Skip isPrimitive check if we know the value must be primitive for a match
1151 // (if array is all primitives, only primitives can match)
1152 if (arrayIsAllPrimitives || isPrimitive(value)) {
1153 return primitiveSet.has(value)
1154 }
1155 return false // Non-primitive can't be in primitive-only set
1156 }
1157
1158 // Fallback: use areValuesEqual for Dates and objects
1159 return array.some((v) => areValuesEqual(v, value))
1160}
1161
1162/**
1163 * Get the maximum of two values, handling both numbers and Dates

Callers 1

minusSameFieldPredicatesFunction · 0.85

Calls 3

isPrimitiveFunction · 0.85
areValuesEqualFunction · 0.70
hasMethod · 0.45

Tested by

no test coverage detected