C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Classes | Functions
MiscUtilities Namespace Reference

Contains various utilities such as computing Damerau–Levenshtein distance and N-dimensional arrays. More...

Classes

struct  ArrayBasedMultiArray
 The ArrayBasedMultiArray struct allows using a fixed size array as underlying container for the MultiArray class. More...
 
class  MultiArray
 The MultiArray class provides an N-dimensional array. More...
 
struct  NoneOwningMultiArray
 The NoneOwningMultiArray struct allows using a caller-managed buffer array as underlying container for the MultiArray class. More...
 
struct  VectorBasedMultiArray
 The VectorBasedMultiArray struct allows using an std::vector with custom allocator as underlying container for the MultiArray class. More...
 
struct  VectorBasedMultiArray< void >
 The VectorBasedMultiArray struct allows using an std::vector as underlying container for the MultiArray class. More...
 

Functions

template<typename ValueType , typename... DimensionSizes>
auto makeMultiArray (DimensionSizes... dimensionSizes)
 Constructs a new N-dimensional array using an std::vector with std::allocator as underlying container. The sizes for the dimensions are passed as arguments. More...
 
template<typename ValueType , std::size_t size, typename... DimensionSizes>
auto makeFixedSizeMultiArray (DimensionSizes... dimensionSizes)
 Constructs a new N-dimensional array using a fixed size array as underlying container. The sizes for the dimensions are passed as arguments. More...
 
template<typename ValueType , typename... DimensionSizes>
auto makeNoneOwningMultiArray (DimensionSizes... dimensionSizes)
 Constructs a new N-dimensional array using a caller-managed buffer as underlying container. The sizes for the dimensions are passed as arguments. More...
 
CPP_UTILITIES_EXPORT std::size_t computeDamerauLevenshteinDistance (const char *str1, std::size_t size1, const char *str2, std::size_t size2)
 
std::size_t computeDamerauLevenshteinDistance (const std::string &str1, const std::string &str2)
 
std::size_t computeDamerauLevenshteinDistance (const char *str1, const char *str2)
 
std::size_t computeDamerauLevenshteinDistance (const char *const str1, const size_t size1, const char *const str2, const size_t size2)
 Computes Damerau–Levenshtein distance with adjacent transpositions. More...
 

Detailed Description

Contains various utilities such as computing Damerau–Levenshtein distance and N-dimensional arrays.

Function Documentation

◆ computeDamerauLevenshteinDistance() [1/4]

CPP_UTILITIES_EXPORT std::size_t MiscUtilities::computeDamerauLevenshteinDistance ( const char *  str1,
std::size_t  size1,
const char *  str2,
std::size_t  size2 
)

◆ computeDamerauLevenshteinDistance() [2/4]

std::size_t MiscUtilities::computeDamerauLevenshteinDistance ( const std::string &  str1,
const std::string &  str2 
)
inline

Definition at line 13 of file levenshtein.h.

◆ computeDamerauLevenshteinDistance() [3/4]

std::size_t MiscUtilities::computeDamerauLevenshteinDistance ( const char *  str1,
const char *  str2 
)
inline

Definition at line 18 of file levenshtein.h.

◆ computeDamerauLevenshteinDistance() [4/4]

std::size_t MiscUtilities::computeDamerauLevenshteinDistance ( const char *const  str1,
const size_t  size1,
const char *const  str2,
const size_t  size2 
)

Computes Damerau–Levenshtein distance with adjacent transpositions.

Returns
Returns the number of editing steps required to turn str1 into str2. The following operations are considered as editing steps:
  • substitution: replace one character with another character
  • insertion: insert one character at any position
  • deletion: delete one character at any position
  • transposition: swap any pair of adjacent characters
Remarks
  • Computing Optimal string alignment distance is a different thing.
  • The algorithm operates on byte-level. So characters requiring more than one byte in the used character encoding (eg. UTF-8 encoded German umlauts) are counted as multiple characters (eg. substitution of those umlauts with non-umlauts requires 2 editing steps).
  • The memory consumption of this algorithm is considerably. The required memory increases with the product of size1 and size2. Pass only short words to this function!

Definition at line 122 of file levenshtein.cpp.

◆ makeFixedSizeMultiArray()

template<typename ValueType , std::size_t size, typename... DimensionSizes>
auto MiscUtilities::makeFixedSizeMultiArray ( DimensionSizes...  dimensionSizes)
inline

Constructs a new N-dimensional array using a fixed size array as underlying container. The sizes for the dimensions are passed as arguments.

Remarks
The number of dimensions N is deduced from the number of dimensionSizes.

Definition at line 174 of file multiarray.h.

◆ makeMultiArray()

template<typename ValueType , typename... DimensionSizes>
auto MiscUtilities::makeMultiArray ( DimensionSizes...  dimensionSizes)
inline

Constructs a new N-dimensional array using an std::vector with std::allocator as underlying container. The sizes for the dimensions are passed as arguments.

Remarks
The number of dimensions N is deduced from the number of dimensionSizes.

Definition at line 166 of file multiarray.h.

◆ makeNoneOwningMultiArray()

template<typename ValueType , typename... DimensionSizes>
auto MiscUtilities::makeNoneOwningMultiArray ( DimensionSizes...  dimensionSizes)
inline

Constructs a new N-dimensional array using a caller-managed buffer as underlying container. The sizes for the dimensions are passed as arguments.

Remarks
The number of dimensions N is deduced from the number of dimensionSizes.

Definition at line 182 of file multiarray.h.