# roaring.container

> A module of roaring's API.

A single Roaring container, keyed externally by a 16-bit high key and holding up to 65536 low-16-bit values in one of three representations.

- **array**: a sorted `List[UInt16]`, used while cardinality <= 4096.
  - **bitset**: a fixed 1024-word (65536-bit) bitset, used above that.
  - **run**: sorted (start, length) runs, used only after `run_optimize()`
    finds it strictly smaller than the array/bitset encoding.

All three representations round-trip through the portable per-container byte
layout described in `portable.mojo`.

## Structs

### `Container`

```mojo
struct Container
```

Implements: `Copyable`, `Movable`

Fields:

- `kind: UInt8`
- `arr: List[UInt16]`
- `bits: List[UInt64]`
- `run_start: List[UInt16]`
- `run_len: List[UInt16]`

#### `__init__`

```mojo
def __init__(out self)
```

#### `cardinality`

```mojo
def cardinality(self) -> Int
```

#### `contains`

```mojo
def contains(self, v: UInt16) -> Bool
```

#### `min_value`

```mojo
def min_value(self) -> UInt16
```

#### `max_value`

```mojo
def max_value(self) -> UInt16
```

#### `to_sorted_list`

```mojo
def to_sorted_list(self) -> List[UInt16]
```

#### `to_bitset_words`

```mojo
def to_bitset_words(self) -> List[UInt64]
```

#### `add`

```mojo
def add(mut self, v: UInt16)
```

#### `remove`

```mojo
def remove(mut self, v: UInt16)
```

#### `run_optimize`

```mojo
def run_optimize(mut self)
```

#### `from_bitset_words`

```mojo
def from_bitset_words(var words: List[UInt64]) -> Self
```

#### `or_`

```mojo
def or_(a, b: Self) -> Self
```

#### `and_`

```mojo
def and_(a, b: Self) -> Self
```

#### `and_not`

```mojo
def and_not(a, b: Self) -> Self
```

#### `xor`

```mojo
def xor(a, b: Self) -> Self
```

#### `serialized_body_size`

```mojo
def serialized_body_size(self) -> Int
```

#### `serialize_body`

```mojo
def serialize_body(self, mut buf: List[UInt8])
```

#### `deserialize_body`

```mojo
def deserialize_body[origin: Origin[mut=origin.mut], //](kind: UInt8, cardinality: Int, data: Span[UInt8, origin], pos: Int) -> Self
```

## Aliases

### `CONTAINER_ARRAY`

```mojo
comptime CONTAINER_ARRAY = UInt8(0)
```

### `CONTAINER_BITSET`

```mojo
comptime CONTAINER_BITSET = UInt8(1)
```

### `CONTAINER_RUN`

```mojo
comptime CONTAINER_RUN = UInt8(2)
```
