Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Trie<T>

Type parameters

  • T

Hierarchy

  • Trie

Index

Constructors

constructor

Properties

__computed

__computed: ITrieRaw<T>

Optional options

options: Readonly<ITrieOptions>

Methods

Protected _checkPrefix

  • _checkPrefix(prefix: string): object

Protected _key

  • _key(word: string): string

addWord

  • addWord(word: string, value?: T): this
  • Add a new word to the trie

    Parameters

    • word: string
    • Default value value: T = null

    Returns this

countPrefix

  • countPrefix(strPrefix: string): number
  • Count the number of words with the given prefixSearch

    Parameters

    • strPrefix: string

    Returns number

    Number

dump

  • dump(spacer?: string | number): string
  • Get a string representation of the trie

    Parameters

    • Default value spacer: string | number = 0

    Returns string

getAnagrams

  • getAnagrams(letters: string): string[]
  • Get a list of valid anagrams that can be made from the given letters

    Parameters

    • letters: string

    Returns string[]

    Array

getPrefix

  • getPrefix(strPrefix: string, sorted?: boolean): string[]
  • Get a list of all words in the trie with the given prefix

    Parameters

    • strPrefix: string
    • Default value sorted: boolean = true

    Returns string[]

    Array

getRandomWordWithPrefix

  • getRandomWordWithPrefix(strPrefix?: string): string
  • Get a random word in the trie with the given prefix

    Parameters

    • Optional strPrefix: string

    Returns string

    String

getSubAnagrams

  • getSubAnagrams(letters: string): string[]
  • Get a list of all sub-anagrams that can be made from the given letters

    Parameters

    • letters: string

    Returns string[]

    Array

getWordData

  • getWordData(word: string, notChkDefault?: boolean): object
  • getWordData<R>(word: string, notChkDefault?: boolean): object
  • example

    tree.getWordData('object.entries') // => { key: 'Object.entries', value: null, matched: false } tree.getWordData('Object.entries') // { key: 'Object.entries', value: null, matched: true }

    Parameters

    • word: string
    • Optional notChkDefault: boolean

    Returns object

    • key: string
    • matched: boolean
    • value: T
  • Type parameters

    • R

    Parameters

    • word: string
    • Optional notChkDefault: boolean

    Returns object

    • key: string
    • matched: boolean
    • value: R

getWordNode

getWordNodeKeys

  • getWordNodeKeys(word: string): string[]
  • example

    tree.getWordNodeKeys('Object.entries') // => [ 'Object.entries' ]

    Parameters

    • word: string

    Returns string[]

getWordsAll

  • getWordsAll(sorted?: boolean): string[]
  • Get all words in the trie

    Parameters

    • Default value sorted: boolean = true

    Returns string[]

    Array

hasWord

  • hasWord(word: string): boolean
  • Check the existence of a word in the trie

    Parameters

    • word: string

    Returns boolean

    Boolean

Protected isAnagrams

  • isAnagrams(letters: string): boolean

isPrefix

  • isPrefix(prefix: string): boolean
  • Check a prefix is valid

    Parameters

    • prefix: string

    Returns boolean

    Boolean

load

  • load(obj: ITrieRaw<T>): this
  • load<R>(obj: ITrieRaw<R>): this
  • load(obj: any): this

removeWord

  • removeWord(word: string, all?: boolean): this
  • Remove an existing word from the trie

    Parameters

    • word: string
    • Optional all: boolean

    Returns this

toRegExp

  • toRegExp<R>(flags?: string, options?: ITrieToRegExpOptions): R
  • toRegExp<R>(flags?: string, options?: ITrieToRegExpOptionsAll<R>): ReturnType<any>
  • Type parameters

    • R

    Parameters

    • Optional flags: string
    • Optional options: ITrieToRegExpOptions

    Returns R

  • Type parameters

    • R

    Parameters

    • Optional flags: string
    • Optional options: ITrieToRegExpOptionsAll<R>

    Returns ReturnType<any>

tree

  • tree(): any

Generated using TypeDoc