# Set algorithms
[BitMagic C++ Library]

Collaboration diagram for Set algorithms:

## Data Structures

class | bm::random_subset< BV >

## Modules

| Distance metrics

## Functions

template<class BV , class It >
void | bm::combine_or (BV &bv, It first, It last)
| OR Combine bitvector and the iterable sequence.
template<class BV , class It >
void | bm::combine_xor (BV &bv, It first, It last)
| XOR Combine bitvector and the iterable sequence.
template<class BV , class It >
void | bm::combine_sub (BV &bv, It first, It last)
| SUB Combine bitvector and the iterable sequence.
template<class BV , class It >
void | bm::combine_and_sorted (BV &bv, It first, It last)
| AND Combine bitvector and the iterable sequence.
template<class BV , class It >
void | bm::combine_and (BV &bv, It first, It last)
| AND Combine bitvector and the iterable sequence.
template<class BV >
bm::id_t | bm::count_intervals (const BV &bv)
| Compute number of bit intervals (GAPs) in the bitvector.
template<class BV , class It >
void | bm::export_array (BV &bv, It first, It last)
| Export bitset from an array of binary data representing the bit vector.

## Detailed Description

Set algorithms

## Function Documentation

template<class BV , class It >

void bm::combine_and | ( | BV & | bv,
|  | It | first,
|  | It | last |
| ) |  |  | `[inline]`

AND Combine bitvector and the iterable sequence.

Algorithm combines bvector with sequence of integers (represents another set). When the agrument set is sorted this method can give serious increase in performance.

Parameters:

  | bv | - destination bitvector
  | first | - first element of the iterated sequence
  | last | - last element of the iterated sequence

See also:
  combine_and_sorted

Definition at line 1418 of file bmalgo_impl.h.

References bm::combine_or().

template<class BV , class It >

void bm::combine_and_sorted | ( | BV & | bv,
|  | It | first,
|  | It | last |
| ) |  |  | `[inline]`

AND Combine bitvector and the iterable sequence.

Algorithm combines bvector with sorted sequence of integers (represents another set).

Parameters:

  | bv | - destination bitvector
  | first | - first element of the iterated sequence
  | last | - last element of the iterated sequence

Definition at line 1386 of file bmalgo_impl.h.

References BM_ASSERT.

template<class BV , class It >

void bm::combine_or | ( | BV & | bv,
|  | It | first,
|  | It | last |
| ) |  |  | `[inline]`

OR Combine bitvector and the iterable sequence.

Algorithm combines bvector with sequence of integers (represents another set). When the agrument set is sorted this method can give serious increase in performance.

Parameters:

  | bv | - destination bitvector
  | first | - first element of the iterated sequence
  | last | - last element of the iterated sequence

Definition at line 1141 of file bmalgo_impl.h.

References bm::block_range_scan(), BM_ASSERT, BMGAP_PTR, bm::gap_limit(), bm::gap_set_value(), bm::id_max, bm::set_block_mask, bm::set_block_shift, bm::set_word_mask, and bm::set_word_shift.

Referenced by bm::combine_and().

template<class BV , class It >

void bm::combine_sub | ( | BV & | bv,
|  | It | first,
|  | It | last |
| ) |  |  | `[inline]`

SUB Combine bitvector and the iterable sequence.

Algorithm combines bvector with sequence of integers (represents another set). When the agrument set is sorted this method can give serious increase in performance.

Parameters:

  | bv | - destination bitvector
  | first | - first element of the iterated sequence
  | last | - last element of the iterated sequence

Definition at line 1304 of file bmalgo_impl.h.

References bm::block_range_scan(), BM_ASSERT, BMGAP_PTR, bm::gap_limit(), bm::gap_set_value(), bm::gap_test(), bm::id_max, bm::set_block_mask, bm::set_block_shift, bm::set_word_mask, and bm::set_word_shift.

template<class BV , class It >

void bm::combine_xor | ( | BV & | bv,
|  | It | first,
|  | It | last |
| ) |  |  | `[inline]`

XOR Combine bitvector and the iterable sequence.

Algorithm combines bvector with sequence of integers (represents another set). When the agrument set is sorted this method can give serious increase in performance.

Parameters:

  | bv | - destination bitvector
  | first | - first element of the iterated sequence
  | last | - last element of the iterated sequence

Definition at line 1220 of file bmalgo_impl.h.

References bm::block_range_scan(), BM_ASSERT, BMGAP_PTR, bm::gap_limit(), bm::gap_set_value(), bm::gap_test(), bm::id_max, bm::set_block_mask, bm::set_block_shift, bm::set_word_mask, and bm::set_word_shift.

template<class BV >

bm::id_t bm::count_intervals | ( | const BV & | bv | ) | `[inline]`

Compute number of bit intervals (GAPs) in the bitvector.

Algorithm traverses bit vector and count number of uninterrupted intervals of 1s and 0s.

        For example:
          00001111100000 - gives us 3 intervals
          10001111100000 - 4 intervals
          00000000000000 - 1 interval
          11111111111111 - 1 interval

Returns:
  Number of intervals

Definition at line 1441 of file bmalgo_impl.h.

References bm::for_each_block().

template<class BV , class It >

void bm::export_array | ( | BV & | bv,
|  | It | first,
|  | It | last |
| ) |  |  | `[inline]`

Export bitset from an array of binary data representing the bit vector.

Input array can be array of ints, chars or other native C types. Method works with iterators, which makes it compatible with STL containers and C arrays

Parameters:

  | bv | - destination bitvector
  | first | - first element of the iterated sequence
  | last | - last element of the iterated sequence

Definition at line 1467 of file bmalgo_impl.h.

References BM_ASSERT, bm::BM_BIT, BMGAP_PTR, bm::set_block_size, and bm::set_total_blocks.