dawgdic
Copyright(c) Andrey Prokopenko 2025
LicenseBSD-3-Clause
Stabilityexperimental
Safe HaskellNone
LanguageGHC2021

Data.DAWG.Internal.DAWGBuilder

Description

 
Synopsis

DAWG Builder

newtype DAWGBuilder (m :: Type -> Type) Source #

A mutable builder of DAWG.

Constructors

DBRef 

data DAWGBuilder_ (m :: Type -> Type) Source #

Builder of DAWG. Do not access directly. Use DAWGBuilder instead.

Constructors

DAWGBuilder 

Fields

numOfStates :: Int Source #

Use it as index for dawgBuilderRefs to get number of states.

numOfMergedTransitions :: Int Source #

Use it as index for dawgBuilderRefs to get number of merged transitions.

numOfMergingStates :: Int Source #

Use it as index for dawgBuilderRefs to get number of merging states.

new :: PrimMonad m => m (DAWGBuilder m) Source #

Creates a new empty DAWGBuilder.

init :: PrimMonad m => DAWGBuilder m -> m () Source #

Initializes empty DAWGBuilder with the root index and the beginning of the word.

insert :: (HasCallStack, PrimMonad m) => Vector Char -> Maybe ValueType -> DAWGBuilder m -> m Bool Source #

Inserts a word with optional value associated to it into DAWGBuilder. Pass Nothing as value if there is no value associated with the word. Returns False if word was not inserted.

insertWithLength :: (HasCallStack, PrimMonad m) => Vector Char -> Int -> ValueType -> DAWGBuilder m -> m Bool Source #

Like insertKey but it also performs input validation. Returns False if word was not inserted.

insertKey Source #

Arguments

:: (HasCallStack, PrimMonad m) 
=> Vector Char

Entire word as vector of keys.

-> Int

Prefix length.

-> ValueType

Value.

-> DAWGBuilder m 
-> m Bool 

Inserts a word (key) with its length and associated value into DAWGBuilder. Pass 0 if there is no value associated with the word. Returns False if word was not inserted.

freeze :: (HasCallStack, PrimMonad m) => DAWGBuilder m -> m DAWG Source #

Generates DAWG out of DAWGBuilder. Once this function is called, DAWGBuilder must not be used anymore.

fromAscList :: (HasCallStack, PrimMonad m) => [String] -> m DAWG Source #

Builds entire DAWG from a lexicon. Lexicon *must be* sorted.

Helpers

allocateUnit :: (HasCallStack, PrimMonad m) => DAWGBuilder m -> m BaseType Source #

Gets a unit from an object pool.

freeUnit :: (HasCallStack, PrimMonad m) => DAWGBuilder_ m -> BaseType -> m () Source #

Adds free unit index to the stack of unused units.

allocateTransition :: (HasCallStack, PrimMonad m) => DAWGBuilder m -> m BaseType Source #

Gets a transition from object pools.

fixUnits :: (HasCallStack, PrimMonad m) => BaseType -> DAWGBuilder m -> m () Source #

Recursively fix units starting from a given index.

expandHashTable :: PrimMonad m => DAWGBuilder m -> m () Source #

Expands supportive hash table by doubling its size.

findTransition :: PrimMonad m => BaseType -> DAWGBuilder m -> m BaseType Source #

Finds suitable transition index.

findUnit :: PrimMonad m => BaseType -> DAWGBuilder m -> m (BaseType, BaseType) Source #

Finds suitable hash id as well as transition index for the given unit.

areEqual :: PrimMonad m => BaseType -> BaseType -> DAWGBuilder m -> m Bool Source #

Checks whether unit index matches with transition index or not.

hashTransition :: PrimMonad m => BaseType -> DAWGBuilder m -> m BaseType Source #

Calculates a hash value from a transition.

hashUnit :: PrimMonad m => BaseType -> DAWGBuilder m -> m BaseType Source #

Calculates a hash value from a unit.

dump :: DAWGBuilder IO -> IO () Source #

Dump builder to stdout.

HashTable helper

resize :: PrimMonad m => DAWGBuilder m -> Int -> m () Source #

Resizes a vector to a given size.

  • If new size is lesser than the table one, it shrinks the table.
  • If new size is greater than the table one, it allocates empty units in the vector to fit new size.
  • Otherwise, it does not do anything.

See it as an equivalent to std::vector.resize().