hhash

package module
v0.0.0-...-53dc8b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2019 License: Unlicense Imports: 7 Imported by: 0

README

hhash

hhash is a consistent, human-readable hashing engine

why

author desired something like the docker container name generator but with consistent hashing and rich custom pattern

installation

$ go get github.com/choey/hhash
$ go get github.com/choey/hhash/cmd/hhash

features

  • supports custom pattern
  • generates random human-readable string
  • generates human-readable hash
  • reports collision rate for the given datasets

futures

  • add dataset for person names
  • scrub datasets to be less offensive

examples

  • random string (which is just the hash of a random UUID)
$ hhash
cedarn_kappa
  • custom pattern (upper case adverb followed by uppercase adjective)
$ hhash -p '[%n-%n]'
[devon-freeware]
  • value hash
$ hhash -s 'hello, world' -v
2019/02/07 23:36:09 using pattern: %j_%n
2019/02/07 23:36:09 elapsed time 373.439µs
fond_bonefish
$ hhash -s 'hello, world' -v
2019/02/07 23:36:33 using pattern: %j_%n
2019/02/07 23:36:33 elapsed time 331.244µs
fond_bonefish

(verbose mode calculates collision rate and thus is slightly slower than non-verbose mode)

attributions

  • WordNet provides the default datasets

Documentation

Overview

Package hhash implements a customizable, human-readable hashing engine.

Index

Constants

This section is empty.

Variables

View Source
var DefaultAdjectives = []string{} /* 1987 elements not displayed */

DefaultAdjectives provide default set of adjects

View Source
var DefaultAdverbs = []string{} /* 1199 elements not displayed */

DefaultAdverbs provide default set of adverbs

View Source
var DefaultDatasetVersion = 1

DefaultDatasetVersion is the version of the default datasets to determine whether two instances of HHash will produce consistent hashes.

View Source
var DefaultNouns = []string{} /* 5000 elements not displayed */

DefaultNouns provide default set of nouns

View Source
var DefaultVerbs = []string{} /* 5000 elements not displayed */

DefaultVerbs provide default set of verbs

View Source
var DefaultVerbsGerund = []string{} /* 401 elements not displayed */

DefaultVerbsGerund provide default set of gerunds ("-ing")

View Source
var DefaultVerbsPast = []string{} /* 1024 elements not displayed */

DefaultVerbsPast provide default set of verbs in the past tense

Functions

This section is empty.

Types

type HHash

type HHash struct {

	// Adjectives is a slice of adjectives
	Adjectives []string
	// Adverbs is a slice of adverbs
	Adverbs []string
	// Adverbs is a slice of nouns
	Nouns []string
	// Verbs is a slice of verbs
	Verbs []string
	// VerbsPast is a slice of verbs in the past tense
	VerbsPast []string
	// VerbsGerund is a slice of verbs in the present participle
	VerbsGerund []string
	// AllowRepeats, if true, allows consecutive tokens to generate the same word (default: false)
	AllowRepeats bool
	// CalculateCollisionRate, if true, calculates the collision rate given the datasets, upon the first hash operation
	CalculateCollisionRate bool
	// contains filtered or unexported fields
}

HHash uses xxhash to generate human-readable hash, with custom pattern and options for various parts of speech.

func New

func New() *HHash

New instantiates an HHash with default datasets.

func NewDefault

func NewDefault() *HHash

NewDefault instantiates an HHash with default datasets and the default pattern.

func NewWDefaultWithPattern

func NewWDefaultWithPattern(pattern string) *HHash

NewWDefaultWithPattern instantiates an HHash with default datasets and the given pattern.

func (*HHash) HashBytes

func (hasher *HHash) HashBytes(bytes []byte) string

HashBytes returns a human-readable hash for the given string.

func (*HHash) HashString

func (hasher *HHash) HashString(s string) string

HashString returns a human-readable hash for the given string.

func (*HHash) HashUint

func (hasher *HHash) HashUint(seed uint64) string

HashUint returns a human-readable hash for the given seed.

func (*HHash) InitPattern

func (hasher *HHash) InitPattern(pattern string) error

InitPattern initializes hhash with a new pattern of word tokens. TODO: examples

func (*HHash) Random

func (hasher *HHash) Random() string

Random returns a human-readable hash based on a random UUID.

func (*HHash) WordsForType

func (hasher *HHash) WordsForType(wordType WordType) []string

WordsForType returns the dataset for the given word type.

type WordCase

type WordCase int

WordCase represents an enumeration of the categories in which a word may be cased.

const (
	// Title casing uppercases the first letter.
	Title WordCase = iota
	// Lower casing lowercases the first letter.
	Lower
)

type WordType

type WordType int

WordType is a semantic type of words that a given token would generate. For example, the token "%A" represents a title-cased Adjective, and the "%v{G}" represents a a lowercased VerbGerund

const (
	// Adjective represents  adjectives.
	Adjective WordType = iota
	// Adverb represents adverbs.
	Adverb
	// Noun represents things and ideas but not persons or places.
	Noun
	// Verb represents actions in their present simple tense ("throw", "eat", "sing").
	Verb
	// VerbPast represents verbs in the past tense.
	VerbPast
	// VerbGerund represents verbs in the present participle tense.
	VerbGerund
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL