Class FrequencyTrie.Builder<V>

java.lang.Object
org.egothor.stemmer.FrequencyTrie.Builder<V>
Type Parameters:
V - value type
Enclosing class:
FrequencyTrie<V>

public static final class FrequencyTrie.Builder<V> extends Object
Builder of FrequencyTrie.

The builder is intentionally mutable and optimized for repeated put(String, Object) calls. The final trie is created by build(), which performs bottom-up subtree reduction and converts the structure to a compact immutable representation optimized for read operations.

  • Constructor Details

    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionSettings reductionSettings)
      Creates a new builder with the provided settings.
      Parameters:
      arrayFactory - array factory
      reductionSettings - reduction configuration
      Throws:
      NullPointerException - if any argument is null
    • Builder

      public Builder(IntFunction<V[]> arrayFactory, ReductionMode reductionMode)
      Creates a new builder using default thresholds for the supplied reduction mode.
      Parameters:
      arrayFactory - array factory
      reductionMode - reduction mode
      Throws:
      NullPointerException - if any argument is null
  • Method Details

    • put

      public FrequencyTrie.Builder<V> put(String key, V value)
      Stores a value for the supplied key and increments its local frequency.

      Values are stored at the node addressed by the full key. Since trie values may also appear on internal nodes, an empty key is valid and stores a value directly at the root.

      Parameters:
      key - key
      value - value
      Returns:
      this builder
      Throws:
      NullPointerException - if key or value is null
    • build

      public FrequencyTrie<V> build()
      Builds a compiled read-only trie.
      Returns:
      compiled trie
    • put

      public FrequencyTrie.Builder<V> put(String key, V value, int count)
      Stores a value for the supplied key and increments its local frequency by the specified positive count.

      Values are stored at the node addressed by the full key. Since trie values may also appear on internal nodes, an empty key is valid and stores a value directly at the root.

      This method is functionally equivalent to calling put(String, Object) repeatedly count times, but it avoids unnecessary repeated map updates and is therefore preferable for bulk reconstruction from compiled tries or other aggregated sources.

      Parameters:
      key - key
      value - value
      count - positive frequency increment
      Returns:
      this builder
      Throws:
      NullPointerException - if key or value is null
      IllegalArgumentException - if count is less than 1