Question

The problem:

1) I have buckets of fixed size, in my case 64. This cannot change.
2) Values vary in size, but are never bigger than a bucket (64).
3) Access is much slower if any element is split between buckets.

Is there some algorithm that computes the optimal order of the elements in the buckets?

There are two variations here, and I'm interested in both, to enable the user of the code to choose between speed and memory usage:

A) Splitting is allowed, but should be minimized.
B) Splitting is not allowed, and padding should be minimized.

Please either post the algorithms, or a link to them, or at least their name, if they are "well known". An Internet search did not return anything useful, probably because the answer was drowned in irrelevant results, like optimal bucket size, and partitioning data in hash-tables.

The target language is Java, but I don't think it should make a difference.

Was it helpful?

Solution

I think you could use memory allocation algorithms, like first fit, best fit, or worst fit (you could read about them here): they are only heuristic approximations of the optimal solution, but I suspect that your original problem is related to the bin-packing problem somehow and may be NP-hard to solve optimally. Try using the approximation algorithms, and split only if you can't place your elements without it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top