From 725239af144246abfc8e13ef50cf8752ba8bfb17 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Sat, 24 Feb 2024 16:53:14 -0700 Subject: [PATCH] Adding examples --- examples/collisions.go | 36 ++++++++++++++++++++++++++++++++++++ examples/default.go | 16 ++++++++++++++++ examples/emojirunes.go | 0 examples/reallylong.go | 0 4 files changed, 52 insertions(+) create mode 100644 examples/collisions.go create mode 100644 examples/default.go create mode 100644 examples/emojirunes.go create mode 100644 examples/reallylong.go diff --git a/examples/collisions.go b/examples/collisions.go new file mode 100644 index 0000000..61d8e1e --- /dev/null +++ b/examples/collisions.go @@ -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{}{} + } +} diff --git a/examples/default.go b/examples/default.go new file mode 100644 index 0000000..0053320 --- /dev/null +++ b/examples/default.go @@ -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()) + } +} diff --git a/examples/emojirunes.go b/examples/emojirunes.go new file mode 100644 index 0000000..e69de29 diff --git a/examples/reallylong.go b/examples/reallylong.go new file mode 100644 index 0000000..e69de29