Added support for the dynamic cache

The C and C++ versions now include support for a dynamic cache, and all
three versions were tweaked slightly in response to benchmarks against
std::stable_sort() in various cases.