A custom implementation of a search trie with the added feature that if there is no branching, then a (sub)word is stored as a sequential data structure. WARNING! The outputs are assumed to be different from the input symbols, as they are used as leaf nodes in the trie when constructing a transducer. The code is separated into two parts: 1. the trie data structure, 2. transducer generation.
A custom implementation of a search trie with the added feature that if there is no branching, then a (sub)word is stored as a sequential data structure. WARNING! The outputs are assumed to be different from the input symbols, as they are used as leaf nodes in the trie when constructing a transducer. The code is separated into two parts: 1. the trie data structure, 2. transducer generation.
(build-trie words)
Builds a trie form a collection of words
Builds a trie form a collection of words
(insert trie word)
Inserts a word into the trie. It takes care of finding the location of mismatch if any.
Inserts a word into the trie. It takes care of finding the location of mismatch if any.
(insert-at trie word [coords pos])
Insert a word into the trie at the location given by search.
Insert a word into the trie at the location given by search.
(mappings-from-trie trie stoppers)
(mappings-from-trie trie stoppers coords state maps)
Recursively constructs state transition mappings from a trie and the output values. The stoppers (the output values) are expected to be in the trie. A counter is maintained through recursion the have a new state if needed. Information traveling in recursion: going-in only: the trie itself (unchanged), coords to pick entries, current state going in and coming back: the maps, the next available state
Recursively constructs state transition mappings from a trie and the output values. The stoppers (the output values) are expected to be in the trie. A counter is maintained through recursion the have a new state if needed. Information traveling in recursion: going-in only: the trie itself (unchanged), coords to pick entries, current state going in and coming back: the maps, the next available state
(outputs-as-stoppers io-pairs)
Puts the outputs into the input words so in a trie for the inputs it is still possible to see the outputs. WARNING! It is assumed that that the inputs and outputs are of different kind!
Puts the outputs into the input words so in a trie for the inputs it is still possible to see the outputs. WARNING! It is assumed that that the inputs and outputs are of different kind!
(retrieve trie)
(retrieve trie so-far result)
Returns all the words stored in the trie.
Returns all the words stored in the trie.
(search trie word)
Searching a word in a trie, reporting the location of mismatch if the word is not in the trie. It returns the the coords (the nested keys) in the trie and the position in the word where the search fails. If the word is fully matched, it returns :matched.
Searching a word in a trie, reporting the location of mismatch if the word is not in the trie. It returns the the coords (the nested keys) in the trie and the position in the word where the search fails. If the word is fully matched, it returns :matched.
(transducer io-pairs)
Creates a transducer for the given input-output pairs by building a trie. Not minimized. Inputs and outputs should have empty intersection!
Creates a transducer for the given input-output pairs by building a trie. Not minimized. Inputs and outputs should have empty intersection!
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |