Adding examples

This commit is contained in:
Matthew Stobbs 2024-02-24 16:53:14 -07:00
parent 7536f525fa
commit 725239af14
4 changed files with 52 additions and 0 deletions

36
examples/collisions.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"log"
"git.staur.ca/stobbsm/tind"
)
var (
longRuneSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}/';:.>,<`~"
shortRuneSet = "0123456789"
)
func CollisionChecks() {
log.Println("Using multiple configurations, test for collisions multiple times")
for i := 0; i < 10; i++ {
log.Printf("Check %d", i)
log.Printf("Using default values, collision after %d iterations", runCheck(tind.Gen().Config()))
}
}
func runCheck(tconfig *tind.Config) uint64 {
var i uint64
tmap := make(map[string]struct{})
for {
i++
t := tconfig.Gen()
if _, ok := tmap[t.String()]; ok {
return i
}
tmap[t.String()] = struct{}{}
}
}

16
examples/default.go Normal file
View File

@ -0,0 +1,16 @@
package main
import (
"fmt"
"git.staur.ca/stobbsm/tind"
)
func GenWithDefaults() {
fmt.Println("Generate 16 different TinD ID's, and print them in both string and byte representations using the default config")
for i := 0; i < 16; i++ {
t := tind.Gen()
fmt.Printf("String: `%s` Bytes: %v\n", t.String(), t.Bytes())
}
}

0
examples/emojirunes.go Normal file
View File

0
examples/reallylong.go Normal file
View File