# Deduplicate records by numeric id

> A Roaring bitset records which ids you have seen in about two bytes per id, or one bit per possible id once ids are dense.

**Few items**

```ts
import { roaringBitset } from 'knotkit/bitset'

const rows = [
  { id: 7, name: 'ada' },
  { id: 4, name: 'grace' },
  { id: 7, name: 'ada' },
]

const seen = roaringBitset()
const unique = rows.filter((row) => {
  if (seen.has(row.id)) {
    return false
  }

  seen.add(row.id)
  return true
})

unique.map((row) => row.name) // ['ada', 'grace']
seen.size // 2
```

**Thousands of items**

```ts
import { roaringBitset } from 'knotkit/bitset'
import { serializeBitset } from 'knotkit/bitset/wire'
import { splitmix32 } from 'knotkit/prng'
import { shuffled } from 'knotkit/sampling'

// 20,000 rows over 10,000 distinct ids, arriving in shuffled order.
const rows = Array.from({ length: 20_000 }, (_, index) => ({ id: index % 10_000, name: `row-${index}` }))
const arrivals = shuffled(splitmix32(2026), rows)

const seen = roaringBitset()
const unique = arrivals.filter((row) => {
  if (seen.has(row.id)) {
    return false
  }

  seen.add(row.id)
  return true
})

unique.length // 10000
seen.size // 10000
serializeBitset(seen).byteLength // 8272, one bit per possible id from 0 to 65,535 rather than one object per row
```

Ids must be integers from 0 to 2³² − 1. For other keys, a `Set` is the right tool.

**Modules:** [`knotkit/bitset`](/modules/bitset/) · [API reference](/reference/knotkit/bitset/)
