Documentation
¶
Overview ¶
Example ¶
package main
import (
"bufio"
"fmt"
"strings"
"github.com/Snawoot/uniqueslice"
)
func main() {
r := strings.NewReader(`123
1234
123`)
scanner := bufio.NewScanner(r)
var handles []uniqueslice.Handle[[]byte, byte]
for scanner.Scan() {
handles = append(handles, uniqueslice.Make(scanner.Bytes()))
}
if err := scanner.Err(); err != nil {
panic(fmt.Errorf("scanner error: %v", err))
}
for i, h := range handles {
fmt.Printf("handles[%d] = %v (%q)\n", i, h.Value(), h.Value())
}
if handles[0] != handles[2] {
panic("handles[0] != handles[2]")
}
if handles[0] == handles[1] {
panic("handles[0] == handles[1]")
}
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handle ¶
type Handle[Slice ~[]T, T comparable] struct { // contains filtered or unexported fields }
Handle is a globally unique identity for some slice of value of type T.
Two handles compare equal exactly if the two values used to create the handles would have also compared equal. The comparison of two handles is trivial and typically much more efficient than comparing the values used to create them.
func Make ¶
func Make[Slice ~[]T, T comparable](s Slice) Handle[Slice, T]
Make returns a globally unique handle for a slice of values of type T. Handles are equal if and only if the values used to produce them are equal. Make is safe for concurrent use by multiple goroutines.
Click to show internal directories.
Click to hide internal directories.