Documentation
¶
Overview ¶
Package gaddag implements the GADDAG, a pretty cool data structure invented by Steven Gordon.
Here we have utility functions for creating a GADDAG.
This is the RPC API for the gaddag package.
Utility functions for doing cool things with gaddags.
Index ¶
- Constants
- func FindHooks(g SimpleGaddag, word string, hookType int) []rune
- func FindInnerHook(g SimpleGaddag, word string, hookType int) bool
- func FindPrefix(g SimpleGaddag, prefix string) bool
- func FindWord(g SimpleGaddag, word string) bool
- func FindWordDawg(g SimpleGaddag, word string) bool
- type Alphabet
- type Arc
- type ArcPtrSlice
- type Gaddag
- type GaddagService
- type GaddagServiceArgs
- type GaddagServiceReply
- type LetterSlice
- type Node
- type NodeArr
- type NodeBucket
- type SimpleDawg
- type SimpleGaddag
- func (g SimpleGaddag) ArcToIdxLetter(arcIdx uint32) (uint32, rune)
- func (g SimpleGaddag) GetAlphabet() *Alphabet
- func (g SimpleGaddag) GetLetterSet(nodeIdx uint32) uint32
- func (g SimpleGaddag) GetRootNodeIndex() uint32
- func (g SimpleGaddag) InLetterSet(letter rune, nodeIdx uint32) bool
- func (g SimpleGaddag) LetterSetAsRunes(nodeIdx uint32) []rune
- func (g SimpleGaddag) NumArcs(nodeIdx uint32) byte
- func (g *SimpleGaddag) SetAlphabet()
Constants ¶
const ( MAX_DEPTH = 16 LETTER_BUCKETS = 100 )
const ( BackHooks = 0 FrontHooks = 1 BackInnerHook = 2 FrontInnerHook = 3 )
const LetterBitLoc = 24
const ( // MaxAlphabetSize is the maximum size of the alphabet, and is also // the "code" for the separation token. MaxAlphabetSize = 31 )
const NumArcsBitLoc = 24
const SeparationToken = '^'
SeparationToken is the GADDAG separation token.
Variables ¶
This section is empty.
Functions ¶
func FindInnerHook ¶ added in v0.0.4
func FindInnerHook(g SimpleGaddag, word string, hookType int) bool
FindInnerHook finds whether the word has a back or front "inner hook", that is, whether if you remove the back or front letter, you can still make a word.
func FindPrefix ¶ added in v0.0.4
func FindPrefix(g SimpleGaddag, prefix string) bool
FindPrefix returns a boolean indicating if the prefix is in the GADDAG. This function is meant to be exported.
func FindWord ¶ added in v0.0.4
func FindWord(g SimpleGaddag, word string) bool
func FindWordDawg ¶ added in v0.0.5
func FindWordDawg(g SimpleGaddag, word string) bool
Finds a word in a SimpleGaddag that is a DAWG. The word can just be found verbatim.
Types ¶
type Alphabet ¶ added in v0.0.4
type Alphabet struct {
// contains filtered or unexported fields
}
This file defines an alphabet. For now, don't create gaddags for alphabets with more than 31 unique runes. Our file format will not yet support it. The vals map has uint32 values for simplicity in serialization. It's ok to waste a few bytes here and there...
func (Alphabet) Letter ¶ added in v0.0.5
Return the letter that this position in the alphabet corresponds to.
func (Alphabet) NumLetters ¶ added in v0.0.5
Return the number of letters in this alphabet.
type ArcPtrSlice ¶
type ArcPtrSlice []*Arc
func (ArcPtrSlice) Len ¶
func (a ArcPtrSlice) Len() int
func (ArcPtrSlice) Less ¶
func (a ArcPtrSlice) Less(i, j int) bool
func (ArcPtrSlice) Swap ¶
func (a ArcPtrSlice) Swap(i, j int)
type Gaddag ¶ added in v0.0.2
type Gaddag struct { Root *Node AllocStates uint32 AllocArcs uint32 SerializedElements []uint32 Alphabet *Alphabet }
Gaddag is a temporary structure to hold the nodes in sequential order prior to writing them to file. It should not be used after making the gaddag.
func GenerateDawg ¶ added in v0.0.5
GenerateDawg makes a GADDAG with only one permutation of letters allowed per word, the spelled-out permutation. We still treat it for all intents and purposes as a GADDAG, but note that it only has one path!
func GenerateGaddag ¶
GenerateGaddag makes a GADDAG out of the filename, and optionally minimizes it and/or writes it to file.
func (*Gaddag) Minimize ¶ added in v0.0.2
func (g *Gaddag) Minimize()
Minimize is a method to minimize the passed-in GADDAG! It works by first calculating the depths and letter sums of all nodes. It uses these values to sort the nodes into a two-dimensional array, to greatly minimize the number of required comparisons.
type GaddagService ¶
type GaddagService struct{}
func (*GaddagService) Generate ¶
func (g *GaddagService) Generate(r *http.Request, args *GaddagServiceArgs, reply *GaddagServiceReply) error
func (*GaddagService) GenerateDawg ¶ added in v0.0.5
func (g *GaddagService) GenerateDawg(r *http.Request, args *GaddagServiceArgs, reply *GaddagServiceReply) error
type GaddagServiceArgs ¶
type GaddagServiceReply ¶
type GaddagServiceReply struct {
Message string `json:"message"`
}
type LetterSlice ¶ added in v0.0.4
type LetterSlice []rune
func (LetterSlice) Len ¶ added in v0.0.4
func (a LetterSlice) Len() int
func (LetterSlice) Less ¶ added in v0.0.4
func (a LetterSlice) Less(i, j int) bool
func (LetterSlice) Swap ¶ added in v0.0.4
func (a LetterSlice) Swap(i, j int)
type Node ¶
type Node struct { Arcs []*Arc NumArcs uint8 LetterSet uint32 // contains filtered or unexported fields }
Node is a temporary type used in the creation of a GADDAG. It will not be used when loading the GADDAG.
type NodeBucket ¶ added in v0.0.2
type NodeBucket [][]NodeArr
type SimpleDawg ¶ added in v0.0.5
type SimpleDawg SimpleGaddag
type SimpleGaddag ¶ added in v0.0.3
type SimpleGaddag struct {
// contains filtered or unexported fields
}
func LoadGaddag ¶ added in v0.0.2
func LoadGaddag(filename string) SimpleGaddag
LoadGaddag loads a gaddag from a file and returns the slice of nodes.
func (SimpleGaddag) ArcToIdxLetter ¶ added in v0.0.3
func (g SimpleGaddag) ArcToIdxLetter(arcIdx uint32) ( uint32, rune)
Finds the index of the node pointed to by this arc and returns it and the letter.
func (SimpleGaddag) GetAlphabet ¶ added in v0.0.5
func (g SimpleGaddag) GetAlphabet() *Alphabet
func (SimpleGaddag) GetLetterSet ¶ added in v0.0.4
func (g SimpleGaddag) GetLetterSet(nodeIdx uint32) uint32
GetLetterSet gets the letter set of the node at nodeIdx.
func (SimpleGaddag) GetRootNodeIndex ¶ added in v0.0.4
func (g SimpleGaddag) GetRootNodeIndex() uint32
GetRootNodeIndex gets the index of the root node.
func (SimpleGaddag) InLetterSet ¶ added in v0.0.4
func (g SimpleGaddag) InLetterSet(letter rune, nodeIdx uint32) bool
InLetterSet returns whether the `letter` is in the node at `nodeIdx`'s letter set.
func (SimpleGaddag) LetterSetAsRunes ¶ added in v0.0.4
func (g SimpleGaddag) LetterSetAsRunes(nodeIdx uint32) []rune
LetterSetAsRunes returns the letter set of the node at `nodeIdx` as a slice of runes.
func (SimpleGaddag) NumArcs ¶ added in v0.0.5
func (g SimpleGaddag) NumArcs(nodeIdx uint32) byte
func (*SimpleGaddag) SetAlphabet ¶ added in v0.0.4
func (g *SimpleGaddag) SetAlphabet()
SetAlphabet recreates the Alphabet structure stored in this SimpleGaddag, and stores it in g.alphabet