Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Substring Maps

Source: lib/substring-map.x

Native counts of borrowed String views.

Include it with #include "substring-map.x".

Primary API

FunctionSummary
MapSubInt.cleanupReleases the record and its backing Blocks, borrowing stored values.
MapSubInt.enumerateInitializes dest to yield canonical (key value) Lists in bucket order.
MapSubInt.incrementAdds one occurrence without copying or interning the word’s bytes.
MapSubInt.iterInitializes dest as a single-pass iterator over boxed values.
MapSubInt.keysInitializes dest as a single-pass iterator over keys in bucket order.
MapSubInt.move_toMoves the record, backing Blocks, and nullable owned contents together.
MapSubInt.newCreates an empty count table in the current Scope.
MapSubInt.scopeAcquires the Map’s scope for explicitly owned contents.
MapSubInt.stringsCopies counts to a Map with canonical String keys in the active pool.
MapSubInt.try_nextYields each unique view and its count without allocating.
MapSubInt.varBoxes map with its registered typed-map tag without copying it.
Var.mapsubintReturns the typed-map pointer carried by value.

MapSubInt

MapSubInt.cleanup

void MapSubInt.cleanup(MapSubInt map)

Releases the record and its backing Blocks, borrowing stored values.

Source: lib/substring-map.x

MapSubInt.enumerate

Iter MapSubInt.enumerate(MapSubInt map, Iter dest)

Initializes dest to yield canonical (key value) Lists in bucket order. The caller owns dest, and the iterator borrows map. Both must remain live during traversal. A null dest returns NULL, and a null map is exhausted. Structural mutation invalidates the iterator.

Each step boxes both fields and interns two List cells. Each cell belongs to the pool owning its canonical match, which may be an ancestor pool, or to the current pool when newly allocated. For MapSubInt, boxing materializes the key as a canonical String and boxes the count. The key follows its actual owning pool. Each MapLongDouble pull allocates its long key as a Var in the current Scope. The yielded List and anything retaining it must stay within that Scope.

Raises: <alloc-fail> or <size-limit> while interning the List. For MapSubInt, materializing the key may raise any cause from Substring.str. For MapLongDouble, boxing the key may raise <alloc-fail> or <bad-enc>. Shared causes do not return from the pull.

Source: lib/substring-map.x

MapSubInt.increment

void MapSubInt.increment(MapSubInt map, Substr word)

Adds one occurrence without copying or interning the word’s bytes. The aggregate count must fit in int.

Source: lib/substring-map.x

MapSubInt.iter

Iter MapSubInt.iter(MapSubInt map, Iter dest)

Initializes dest as a single-pass iterator over boxed values. The caller owns dest, and the iterator borrows map; both must remain live during traversal. A null dest returns NULL. Values follow bucket order, a null map is exhausted, and structural mutation invalidates the iterator.

Source: lib/substring-map.x

MapSubInt.keys

Iter MapSubInt.keys(MapSubInt map, Iter dest)

Initializes dest as a single-pass iterator over keys in bucket order. The caller owns dest, and the iterator borrows map. Both must remain live during traversal. A null dest returns NULL, and a null map is exhausted. Structural mutation invalidates the iterator.

Each MapSubInt pull materializes the key as a canonical String with Substring.str. The result follows its actual owning pool. MapIntInt and both String-keyed families box keys without allocation. Each MapLongDouble pull allocates its long key as a Var in the current Scope. The yielded Var and anything retaining it must stay within that Scope.

Raises: for MapSubInt, the causes from Substring.str while materializing a key. For MapLongDouble, <alloc-fail> or <bad-enc> while boxing a key.

Source: lib/substring-map.x

MapSubInt.move_to

void MapSubInt.move_to(MapSubInt map, Scope *destination)

Moves the record, backing Blocks, and nullable owned contents together. Pointers and references remain unchanged. The destination slot acquires a scope if empty. NULL maps do nothing.

Raises: <bad-arg> for a NULL destination slot, or <alloc-fail> while creating its scope. Those failures leave ownership unchanged.

Source: lib/substring-map.x

MapSubInt.new

MapSubInt MapSubInt.new(void)

Creates an empty count table in the current Scope.

Source: lib/substring-map.x

MapSubInt.scope

Scope MapSubInt.scope(MapSubInt map)

Acquires the Map’s scope for explicitly owned contents. Created lazily beneath the record’s owner, this scope excludes the record and backing Blocks. Stored references remain borrowed unless explicitly moved into it. NULL returns NULL.

Raises: <alloc-fail> when creating the scope.

Source: lib/substring-map.x

MapSubInt.strings

Map MapSubInt.strings(MapSubInt map)

Copies counts to a Map with canonical String keys in the active pool.

Source: lib/substring-map.x

MapSubInt.try_next

int MapSubInt.try_next(MapSubInt map, unsigned &cursor, Substr &word, int &count)

Yields each unique view and its count without allocating.

Source: lib/substring-map.x

MapSubInt.var

Var MapSubInt.var(MapSubInt map)

Boxes map with its registered typed-map tag without copying it. The typed pointer and Var share the same mutable map identity.

Source: lib/substring-map.x

Var

Var.mapsubint

MapSubInt Var.mapsubint(Var value)

Returns the typed-map pointer carried by value. value must carry this family’s registered tag; the converter does not validate the tag before reading its pointer payload.

Source: lib/substring-map.x

Advanced and interop API

FunctionSummary
MapSubInt.new_capacityCreates an empty count table with exactly capacity buckets in the current Scope.

MapSubInt

MapSubInt.new_capacity

MapSubInt MapSubInt.new_capacity(unsigned capacity)

Creates an empty count table with exactly capacity buckets in the current Scope. Presizing for the expected number of distinct words avoids regrowth; the table still grows past three-quarters full.

Raises: <bad-arg> unless capacity is a power of two of at least two.

Source: lib/substring-map.x

Public types

TypeKindSummary
MapSubIntstructA scope-owned count table that borrows Substr keys.

MapSubInt

typedef struct MapSubInt { Scope scope, Bytes hashes, entries; unsigned used, capacity, mask; } *MapSubInt

A scope-owned count table that borrows Substr keys. Keep every source String alive and unchanged until the table’s final use. Counting copies only the view; strings() materializes each unique key once. Context export preserves the table and exports the source Strings used by its views.

Source: lib/substring-map.x

Examples