BitSorter.hpp

A quick series of comparisons intended for sorting bits.

class BitSorter
#include <BitSorter.hpp>

Public Types

using bits_t = uint32_t

Type used to represent pairs if positions as bit masks.

Public Functions

inline BitSorter()
BitSorter(const BitSorter&) = default
BitSorter(BitSorter&&) = default
inline ~BitSorter()
BitSorter &operator=(const BitSorter&) = default
BitSorter &operator=(BitSorter&&) = default
inline bool operator!=(const BitSorter &other) const
inline bool operator<(const BitSorter &other) const
inline size_t GetSize() const

How many comparators are in this sorting network.

inline size_t size() const
inline std::pair<size_t, size_t> GetComparator(size_t idx)
inline bits_t &operator[](size_t idx)
inline bits_t GetBits(size_t idx)
inline void Clear()
inline void CalcDepth(size_t num_bits, vector<size_t> &depth_vals) const

If this network is compressed as far as possible, what will the max depth of each position be?

inline size_t CalcDepth(size_t num_bits = 16) const

Return only the highest overall depth of the sorting network.

inline bool AddCompare(size_t id1, size_t id2)

Push a new comparator onto the back of the list.

inline bool EditCompare(size_t pos, size_t id1, size_t id2)

Change the positions compared in a specified comparator.

inline bool InsertCompare(size_t pos, size_t id1, size_t id2)

Insert a new comparator at the specified position.

inline bool RemoveCompare(size_t pos)

Remove the comparator at the specified position.

inline bits_t Sort(bits_t values) const

Run a specific set of bit values through the series of comparators in this sorting network.

inline bool TestSortable(bits_t values) const

Determine if a particular input bit pattern will be sorted correctly by this network.

inline size_t CountSortable(size_t num_bits = 16) const

Try all possible bit sequences (with the specified number of bits) and count how many this sorting network fully sorts.

inline std::string AsString() const

Describe this sorting network in a string, listing all comparators in order.

Public Static Functions

static inline bits_t RunCompare(bits_t values, bits_t comparator)

Run a specific set of bit values through a single comparator.

static inline std::string ToString(bits_t values, size_t num_bits = 16)

Convert a specified set of values to an std::string of 0’s and 1’s.

Protected Attributes

vector<bits_t> compare_set

Comparators, in order (pairs of 1’s in bitstring)