Adding examples
This commit is contained in:
parent
7536f525fa
commit
725239af14
36
examples/collisions.go
Normal file
36
examples/collisions.go
Normal 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
16
examples/default.go
Normal 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
0
examples/emojirunes.go
Normal file
0
examples/reallylong.go
Normal file
0
examples/reallylong.go
Normal file
Loading…
Reference in New Issue
Block a user