Primitive, binary-search Distribution object#67
Primitive, binary-search Distribution object#67incaseoftrouble wants to merge 1 commit intoprismmodelchecker:masterfrom
Conversation
|
I have the following questions:
I am also very sceptical considering the fact that the entries you use for iteration are mutable. This is a sure source for hard-to-track bugs, as it imposes a very different contract than before. Also, you can write the underlying structure during iteration which might be undesirable. |
Only a few local tests. If exhaustive testing is wished for I can do it. The primary goal was memory efficiency, in the limit this implementation is probably worse than optimal hashing (log n vs constant ...)
I'd love to, but that makes the changes quite global. The best / modern approach would be to have
Its slower due to boxing/unboxing. This basically is taken from my local branch where I replaced everything with primitive data structures. Can easily be adapted and is quite related to the the
There are multiple things I think: b) Mutation through the entry: This can easily be controlled by exceptions. Wasn't it mutable before? c) Mutation of the structure while iterating: Well, fail-fast is only required to be best-effort. It can be done with slightly more memory and runtime but I think its not worth it. Especially, since the object should be immutable anyway ... |
ca12ca0 to
6bf73df
Compare
An improvement of the Distribution using two arrays and binary search, yielding significantly smaller memory footprint. Avoiding repeated boxing and unboxing yields noticeable speed-ups.
Repeated calls to
add()have a worse complexity (theta n per call), hence a bulk constructor and a builder with amortized n log n construction complexity (for the whole distribution) is added.