barrel_postings (barrel_docdb v1.0.0)

View Source

Postings Resource API for barrel_docdb

This module wraps the rocksdb postings_* resource API for efficient posting list operations. The resource API parses posting list binaries once and provides O(1) or O(log n) lookups for repeated access.

Key benefits: - Parse once, lookup many times (~0.1 us per lookup) - Native set operations (intersection, union, difference) - Pre-sorted keys in V2 format - Roaring64 bitmap for fast existence checks

Summary

Functions

Check if a key exists using the embedded roaring bitmap. O(1) hash-based lookup, may have rare false positives. Use contains/2 for exact checks when false positives are unacceptable.

Check if a key exists in the posting list (exact match). Uses O(log n) binary search on sorted keys.

Get the number of active keys in the posting list.

Compute difference (A - B) of two posting lists. Returns keys in A that are not in B.

Compute intersection of multiple posting lists. Efficiently processes smallest lists first. All list elements can be postings resources or binaries.

Compute intersection (AND) of two posting lists. Both arguments can be postings resources or binaries.

Get the cardinality of intersection without materializing the result. Uses roaring bitmap for fast computation.

Get all active keys in lexicographic (sorted) order. Keys are pre-sorted in V2 format, so this is O(n).

Parse a posting list binary into a resource for fast repeated lookups. The binary must be a valid V1 or V2 posting list format.

Convert a postings resource back to binary format.

Compute union (OR) of two posting lists. Both arguments can be postings resources or binaries.

Types

postings/0

-opaque postings()

Functions

bitmap_contains(Postings, Key)

-spec bitmap_contains(postings(), binary()) -> boolean().

Check if a key exists using the embedded roaring bitmap. O(1) hash-based lookup, may have rare false positives. Use contains/2 for exact checks when false positives are unacceptable.

contains(Postings, Key)

-spec contains(postings(), binary()) -> boolean().

Check if a key exists in the posting list (exact match). Uses O(log n) binary search on sorted keys.

count(Postings)

-spec count(postings()) -> non_neg_integer().

Get the number of active keys in the posting list.

difference(A, B)

-spec difference(postings() | binary(), postings() | binary()) -> {ok, postings()} | {error, term()}.

Compute difference (A - B) of two posting lists. Returns keys in A that are not in B.

intersect_all(Postings)

-spec intersect_all([postings() | binary()]) -> {ok, postings()} | {error, term()}.

Compute intersection of multiple posting lists. Efficiently processes smallest lists first. All list elements can be postings resources or binaries.

intersection(A, B)

-spec intersection(postings() | binary(), postings() | binary()) -> {ok, postings()} | {error, term()}.

Compute intersection (AND) of two posting lists. Both arguments can be postings resources or binaries.

intersection_count(A, B)

-spec intersection_count(postings() | binary(), postings() | binary()) -> non_neg_integer().

Get the cardinality of intersection without materializing the result. Uses roaring bitmap for fast computation.

keys(Postings)

-spec keys(postings()) -> [binary()].

Get all active keys in lexicographic (sorted) order. Keys are pre-sorted in V2 format, so this is O(n).

open(Binary)

-spec open(binary()) -> {ok, postings()} | {error, term()}.

Parse a posting list binary into a resource for fast repeated lookups. The binary must be a valid V1 or V2 posting list format.

to_binary(Postings)

-spec to_binary(postings()) -> binary().

Convert a postings resource back to binary format.

union(A, B)

-spec union(postings() | binary(), postings() | binary()) -> {ok, postings()} | {error, term()}.

Compute union (OR) of two posting lists. Both arguments can be postings resources or binaries.