Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework for custom "item comparators" #13

Open
Bulat-Ziganshin opened this issue Jul 2, 2018 · 0 comments
Open

Framework for custom "item comparators" #13

Bulat-Ziganshin opened this issue Jul 2, 2018 · 0 comments

Comments

@Bulat-Ziganshin
Copy link

Bulat-Ziganshin commented Jul 2, 2018

I propose to make the following framework for custom "item comparators", and to implement built-in functionality on top of it.

Low-level API allows user to choose how many buckets are used on each pass:

template <class LowLevelCustomComparator>
class LowLevelSorter {...}  // Here we should perform all the real work!

template <typename T>
class LowLevelCustomComparator
{
    // Total number of radix-sort passes over data or 0 for variable amount
    static int passes;

    // How many buckets to use on this pass
    template <int pass>  static int buckets();

    // Compute bucket from the item
    template <int pass>  static int bucket (T item);

    // Bucket used for items that don't need any more sorting, i.e. 0 for strings
    template <int pass>  static int final_bucket();
}

High-level API just tells how many bits in the sort key. Library provides implementation of this API that calls into the low-level API using optimal (for this particular box) settings for each pass:

template <class HighLevelCustomComparator>
class HighLevelSorter {...}

template <typename T>
class HighLevelCustomComparator
{
    // Total number of bits in the key or 0 for variable amount
    static int bits;

    // Compute bucket from the item for some pass
    template<int first_bit, int last_bit>  static int bucket (T item);

    // Bucket used for items that don't need any more sorting, i.e. 0 for strings
    template<int first_bit, int last_bit>  static int final_bucket();
}

Finally, highest-level code should implement standard sorting of standard C++ types by constructing HighLevelCustomComparator from the type and provide user with tools to construct comparator f.e. for selected fields in the structure.

@Bulat-Ziganshin Bulat-Ziganshin changed the title Framework for custom "item compare" functions Framework for custom "item comparators" Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant