# `ExVrp.DynamicBitset`
[🔗](https://github.com/sephianl/ex_vrp/blob/v0.4.2/lib/ex_vrp/dynamic_bitset.ex#L1)

A dynamic bitset for fast membership checks on integers.

This is useful for tracking which clients are in a solution, which routes
have been visited, etc. The bitset is immutable - all operations return
a new bitset.

The size is rounded up to the nearest multiple of 64 bits.

## Example

    bitset = ExVrp.DynamicBitset.new(128)
    bitset = ExVrp.DynamicBitset.set(bitset, 0, true)
    bitset = ExVrp.DynamicBitset.set(bitset, 64, true)
    ExVrp.DynamicBitset.count(bitset)  # => 2

# `t`

```elixir
@type t() :: reference()
```

# `all?`

```elixir
@spec all?(t()) :: boolean()
```

Returns true if all bits are set.

# `any?`

```elixir
@spec any?(t()) :: boolean()
```

Returns true if any bit is set.

# `bit_and`

```elixir
@spec bit_and(t(), t()) :: t()
```

Bitwise AND of two bitsets. Returns a new bitset.

# `bit_not`

```elixir
@spec bit_not(t()) :: t()
```

Bitwise NOT of a bitset. Returns a new bitset.

# `bit_or`

```elixir
@spec bit_or(t(), t()) :: t()
```

Bitwise OR of two bitsets. Returns a new bitset.

## Example

    result = ExVrp.DynamicBitset.bit_or(bitset1, bitset2)

# `bit_xor`

```elixir
@spec bit_xor(t(), t()) :: t()
```

Bitwise XOR of two bitsets. Returns a new bitset.

# `count`

```elixir
@spec count(t()) :: non_neg_integer()
```

Returns the number of set bits.

# `equal?`

```elixir
@spec equal?(t(), t()) :: boolean()
```

Checks if two bitsets are equal.

# `get`

```elixir
@spec get(t(), non_neg_integer()) :: boolean()
```

Gets the bit at the given index.

## Example

    ExVrp.DynamicBitset.get(bitset, 0)  # => false

# `new`

```elixir
@spec new(non_neg_integer()) :: t()
```

Creates a new bitset with the given number of bits.

The actual size is rounded up to the nearest multiple of 64.

## Example

    bitset = ExVrp.DynamicBitset.new(128)

# `none?`

```elixir
@spec none?(t()) :: boolean()
```

Returns true if no bits are set.

# `reset_all`

```elixir
@spec reset_all(t()) :: t()
```

Resets all bits to 0. Returns a new bitset.

# `set`

```elixir
@spec set(t(), non_neg_integer(), boolean()) :: t()
```

Sets the bit at the given index. Returns a new bitset.

## Example

    bitset = ExVrp.DynamicBitset.set(bitset, 0, true)

# `set_all`

```elixir
@spec set_all(t()) :: t()
```

Sets all bits to 1. Returns a new bitset.

# `size`

```elixir
@spec size(t()) :: non_neg_integer()
```

Returns the size (length) of the bitset.

This is the actual allocated size (rounded up to 64-bit blocks).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
