Skip to main content

dsa

Copyright 2026 ResQ Software. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Probabilistic set membership data structure Space-efficient probabilistic data structure that tests whether an element is a member of a set. May produce false positives but never false negatives. Use cases:
  • Quick membership checks for large sets
  • Spam filtering
  • Distributed cache lookup
  • Network packet deduplication
:::note False positive rate is configurable at construction ::: :::warning Not suitable for security-critical membership tests ::: :::warning Cannot remove elements (use CountingBloomFilter instead) :::

Example:

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Count-Min sketch for frequency estimation Probabilistic data structure for estimating frequencies of events. Provides space-efficient counting with guaranteed error bounds. Use cases:
  • Network traffic analysis
  • Heavy hitter detection
  • Approximate frequency queries
:::note Guarantees estimate >= true count (upper bound) ::: :::note Actual error is at most eps * N with probability delta ::: :::warning Not suitable for exact counting :::

Example:

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Graph data structures and pathfinding algorithms Provides generic graph representation with common pathfinding algorithms. Supports both unweighted and weighted edges with Dijkstra and A* search. :::note Uses adjacency list representation for memory efficiency ::: :::note Id type must be hashable and equality-comparable :::

Example:

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Fixed-size priority queue with bounded capacity A bounded min-heap that maintains at most N elements, automatically evicting the element with the highest distance value when full. Useful for K-nearest-neighbors, top-K selection, and beam search. :::note Uses max-heap internally (highest distance at root), but exposes the element with minimum distance value as the “best” ::: :::warning The comparison function must be consistent - if f(a) < f(b) and f(b) < f(c), then f(a) < f(c) :::

Example:

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Trie (prefix tree) and string matching algorithms Provides efficient string data structures for:
  • Prefix-based autocomplete
  • String storage and lookup
  • Pattern matching
:::note Uses case-sensitive ASCII character comparison ::: :::warning Not suitable for Unicode strings without modification :::

Example:

Classes

Functions


rabin_karp

inline
Rabin-Karp string matching algorithm. Uses rolling hash for O(n + m) average-case string matching. Useful for finding all occurrences of a pattern in text.

Parameters

  • text Text to search in
  • pat Pattern to search for

Returns

Vector of starting positions where pattern matches :::note Uses base 31 with modulo 1,000,000,007 ::: :::note False matches are possible due to hash collisions :::

Example: