Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

Public Types | Static Public Member Functions | Static Private Member Functions | List of all members
core_lib::sorting::Bucket< T, Pred > Class Template Reference

Templated static class to perform a bucket sort. More...

`#include <GenericSorting.h>`

## Public Types
using | item_compare = Pred
| Public typedef for predicate.
using | bucket_definitions = std::vector< std::pair< T, T > >
| Public typedef for bucket definitions.
using | bucket_values = std::vector< std::list< T > >
| Public typedef for bucket values.

## Static Public Member Functions
template<typename TIterator >
static void | Sort (TIterator begin, TIterator end, const bucket_definitions &bucketDefinitions, bucket_values &bucketValues)
| In-place static sort function. More...
template<typename TIterator >
static void | Sort (TIterator begin, TIterator end, const bucket_definitions &bucketDefinitions)
| Static sort function. More...

## Static Private Member Functions
static void | CheckBucketsSize (const bucket_definitions &bucketDefinitions, bucket_values &bucketValues)
| Static function to check bucket values collection size. More...
static size_t | GetBucketIndex (const T &value, const bucket_definitions &bucketDefinitions)
| Static compute the correct bucket index for a given item. More...
template<typename TIterator >
static void | PutIntoBuckets (TIterator begin, TIterator end, const bucket_definitions &bucketDefinitions, bucket_values &bucketValues)
| Static to put the items in to the correct buckets. More...
template<typename TIterator >
static void | WriteBackBuckets (TIterator begin, const bucket_values &bucketValues)
| Static to move the items from the buckets back into the original collection. More...
template<typename TIterator >
static void | SortResult (TIterator begin, TIterator end)
| Static method to perform a final sort on the collection. More...

## Detailed Description

### template<typename T, typename Pred = std::less<T>>
class core_lib::sorting::Bucket< T, Pred >

Templated static class to perform a bucket sort.

Template args are T, the type of value to be sorted, and Pred, the comparison functor to compare items of type T. The default comparison predicate is std::less<T>.

## Member Function Documentation

## ◆ CheckBucketsSize()

template<typename T , typename Pred = std::less<T>>

static void core_lib::sorting::Bucket< T, Pred >::CheckBucketsSize | ( | const bucket_definitions & | bucketDefinitions,
|  | bucket_values & | bucketValues
| ) |  |
| inline static private

Static function to check bucket values collection size.

Parameters

  [in] | bucketDefinitions | - The definition of the ranges of the different buckets, e.g. the min and max values per bucket.
  [in] | bucketValues | - The bucket values collection.

This function compares the size of the bucket values collection to that of the bucket definitions collection and resizes the bucket value collection if required.

## ◆ GetBucketIndex()

template<typename T , typename Pred = std::less<T>>

static size_t core_lib::sorting::Bucket< T, Pred >::GetBucketIndex | ( | const T & | value,
|  | const bucket_definitions & | bucketDefinitions
| ) |  |
| inline static private

Static compute the correct bucket index for a given item.

Parameters

  [in] | value | - The item to put in to a bucket.
  [in] | bucketDefinitions | - The definition of the ranges of the different buckets, e.g. the min and max values per bucket.

This function iterates over the buckets until it finds the correct one to hold the given item.

## ◆ PutIntoBuckets()

template<typename T , typename Pred = std::less<T>>
template<typename TIterator >

static void core_lib::sorting::Bucket< T, Pred >::PutIntoBuckets | ( | TIterator | begin,
|  | TIterator | end,
|  | const bucket_definitions & | bucketDefinitions,
|  | bucket_values & | bucketValues
| ) |  |
| inline static private

Static to put the items in to the correct buckets.

Parameters

  [in] | begin | - The begining of the collection to sort.
  [in] | end | - The end of the collection to sort (in STL fashion this is the item just after the last otem to be sorted).
  [in] | bucketDefinitions | - The definition of the ranges of the different buckets, e.g. the min and max values per bucket.
  [out] | bucketValues | - The collection of buckets containing the values for each bucket range.

This function builds up the buckets with the correct items.

## ◆ Sort() [1/2]

template<typename T , typename Pred = std::less<T>>
template<typename TIterator >

static void core_lib::sorting::Bucket< T, Pred >::Sort | ( | TIterator | begin,
|  | TIterator | end,
|  | const bucket_definitions & | bucketDefinitions,
|  | bucket_values & | bucketValues
| ) |  |
| inline static

In-place static sort function.

Parameters

  [in] | begin | - The begining of the collection to sort.
  [in] | end | - The end of the collection to sort (in STL fashion this is the item just after the last item to be sorted).
  [in] | bucketDefinitions | - The definition of the ranges of the different buckets, e.g. the min and max values per bucket.
  [out] | bucketValues | - The collection of buckets containing the values for each bucket range.

This function sorts a collection (vector, list etc) of items of type T between a begin and end iterator. This version can be used when the user is interested in gaining access to the intermediate collection of buckets containing the partitioned values.

## ◆ Sort() [2/2]

template<typename T , typename Pred = std::less<T>>
template<typename TIterator >

static void core_lib::sorting::Bucket< T, Pred >::Sort | ( | TIterator | begin,
|  | TIterator | end,
|  | const bucket_definitions & | bucketDefinitions
| ) |  |
| inline static

Static sort function.

Parameters

  [in] | begin | - The begining of the collection to sort.
  [in] | end | - The end of the collection to sort (in STL fashion this is the item just after the last item to be sorted).
  [in] | bucketDefinitions | - The definition of the ranges of the different buckets, e.g. the min and max values per bucket.

This function sorts a collection (vector, list etc) of items of type T between a begin and end iterator. This version can be used when the user is only interested in the final result.

## ◆ SortResult()

template<typename T , typename Pred = std::less<T>>
template<typename TIterator >

static void core_lib::sorting::Bucket< T, Pred >::SortResult | ( | TIterator | begin,
|  | TIterator | end
| ) |  |
| inline static private

Static method to perform a final sort on the collection.

Parameters

  [in] | begin | - The beginning of the collection to sort.
  [in] | end | - The end of the collection to sort (in STL fashion this is the item just after the last otem to be sorted).

This function performs an insertion sort on the modified bucket ordered collection to obtain the sorted result.

## ◆ WriteBackBuckets()

template<typename T , typename Pred = std::less<T>>
template<typename TIterator >

static void core_lib::sorting::Bucket< T, Pred >::WriteBackBuckets | ( | TIterator | begin,
|  | const bucket_values & | bucketValues
| ) |  |
| inline static private

Static to move the items from the buckets back into the original collection.

Parameters

  [in] | begin | - The begining of the collection to sort.
  [in] | bucketValues | - The collection of buckets containing the values for each bucket range.

This function moves each bucket item, in bucket order, back into the original collection, overwriting the original collection. After calling this method the collection still needs a final sort performed.

The documentation for this class was generated from the following file:

- D:/Projects/CoreLibrary/Include/Sorting/GenericSorting.h