keys/words/wordcodec.go
func (c *WordCodec) GetIndex(word string) (int, error) {
	// generate the first time
	if c.bytes == nil {
		b := map[string]int{}
		for i, w := range c.words {
			if _, ok := b[w]; ok {
				return -1, errors.Errorf("Duplicate word in list: %s", w)
			}
			b[w] = i
		}
		c.bytes = b
	}

	// get the index, or an error
	rem, ok := c.bytes[word]
	if !ok {
		return -1, errors.Errorf("Unrecognized word: %s", word)
	}
	return rem, nil
}
func (c *WordCodec) GetIndex(word string) (int, error) {
	// generate the first time
	if c.bytes == nil {
		b := map[string]int{}
		for i, w := range c.words {
			if _, ok := b[w]; ok {
				return -1, errors.Errorf("Duplicate word in list: %s", w)
			}
			b[w] = i
		}
		c.bytes = b
	}

	// get the index, or an error
	rem, ok := c.bytes[word]
	if !ok {
		return -1, errors.Errorf("Unrecognized word: %s", word)
	}
	return rem, nil
}
func ( c * WordCodec ) GetIndex ( word string ) ( int , error ) { // generate the first time if c . bytes == nil { b := map [ string ] int { } for i , w := range c . words { if _ , ok := b [ w ] ; ok { return - 1 , errors . Errorf ( " " , w ) } b [ w ] = i } c . bytes = b } // get the index, or an error rem , ok := c . bytes [ word ] if ! ok { return - 1 , errors . Errorf ( " " , word ) } return rem , nil }
// GetIndex finds the index of the words to create bytes
// Generates a map the first time it is loaded, to avoid needless
// computation when list is not used.
GetIndex finds the index of the words to create bytes Generates a map the first time it is loaded to avoid needless computation when list is not used .