# Set Similarity

> NumKong for Go

Hamming and Jaccard distances for binary and set-hash vectors.

```go
// Byte-level Hamming distance
a := []uint8{1, 2, 3, 4}
b := []uint8{1, 0, 3, 5}
dist := nk.HammingU8(a, b) // 2

// Bit-level Hamming distance (packed binary vectors)
x := []byte{0xFF}
y := []byte{0x0F}
bits := nk.HammingU1(x, y, 8) // 4

// Bit-level Jaccard distance
jd := nk.JaccardU1(x, y, 8) // 0.5

// Set-hash Jaccard (MinHash-style)
h16a := []uint16{1, 2, 3, 4}
h16b := []uint16{3, 4, 5, 6}
nk.JaccardU16(h16a, h16b)

h32a := []uint32{10, 20, 30}
h32b := []uint32{30, 40, 50}
nk.JaccardU32(h32a, h32b)
```

`import "github.com/ashvardanian/NumKong"`

## HammingU1

HammingU1 computes the Hamming distance between two binary vectors of depth dimensions, a multiple of 8, and both slices hold at least [DimensionsToValues]("u1", depth) bytes.

```go
func HammingU1(a, b []byte, depth int) uint32
```

## HammingU8

HammingU8 counts the positions at which two uint8 vectors differ.

```go
func HammingU8(a, b []uint8) uint32
```

Both slices must have the same length.

## JaccardU1

JaccardU1 computes the Jaccard distance between two binary vectors of depth dimensions, a multiple of 8, and both slices hold at least [DimensionsToValues]("u1", depth) bytes.

```go
func JaccardU1(a, b []byte, depth int) float32
```

## JaccardU16

JaccardU16 computes the Jaccard distance between two uint16 set-hash vectors.

```go
func JaccardU16(a, b []uint16) float32
```

Both slices must have the same length.

## JaccardU32

JaccardU32 computes the Jaccard distance between two uint32 set-hash vectors.

```go
func JaccardU32(a, b []uint32) float32
```

Both slices must have the same length.

