Open DK96-OS opened 2 years ago
The recent changes in Primes
included the addition of a private array insertion method, complementing the existing private readFromArray
method. These two methods encapsulate the internal array data storage, and any transformations that are to be applied when reading and writing the array.
The array data encapsulation is highly effective, supporting quick and easy upgrade in #124
There are many creative solutions, each introducing some amount of complexity. It is important to determine what the ideal balance of memory and cpu usage is during operations, and throughout the life of the cache.
For example, does dividing the size of the data array in half outweigh a doubling of branches, or a significant increase in the number of arithmetic operations?
A reliable series of measurements of cpu time performance comparing the solutions will be used in the decision. These will be contrasted with the theoretical memory saved, including the ability of the solution to scale to larger prime numbers.
Upgrade the
BytePrimeCache
using properties of small prime numbers to reduce the space requirement, and extend the coverage (ie. increase maxIndex).A succinct or compact data structure uses space on the order of the minimum number of bits required to represent each element.
A basic fact to get started with:
This could increase the
maxIndex
(up to double the highest prime) by adding a bit shift operation when the index is between the currentmaxIndex
, and the newmaxIndex
.