Library Development: What to finish/flesh out?

dsimcha dsimcha at yahoo.com
Thu Mar 17 15:25:58 PDT 2011


On 3/17/2011 6:18 PM, spir wrote:
> I'd have much use for both below.
>
> On 03/17/2011 04:33 PM, dsimcha wrote:
>> 1. Rational: A library for handling rational numbers exactly.
>> Templated on
>> integer type, can use BigInts for guaranteed accuracy, or fixed-width
>> integers
>> for more speed where the denominator and numerator will be small.
>> Completion
>> state: Mostly finished. Just need to fix a litte bit rot and submit for
>> review. (Phobos candidate)
>
> For decimal exactitude, what about plain fixed point (with decimal
> factor and binary mantissa)?
>

I wouldn't mind having this, but I see it as completely orthogonal to 
rational numbers and don't have any near-term intentions of implementing it.

>> 2. RandAA: A hash table implementation with deterministic memory
>> management,
>> based on randomized probing. Main advantage over builtin AAs is that
>> it plays
>> much nicer with the GC and multithreaded programs. Lookup times are also
>> expected O(1) no matter how many collisions exist in modulus hash
>> space, as
>> long as there are few collisions in full 32- or 64-bit hash space.
>> Completion
>> state: Mostly finished. Just needs a little doc improvement, a few
>> benchmarks and submission for review. (Phobos candidate)
>
> How complicated would it be to add (optional) support for keeping
> insertion order (for iteration only)? Thought at a // array with
> pointers to the cells holding key/value pairs.

It's a good idea, but IMHO something like this should be templated on 
the type of the associative array and work with builtin AAs, etc., too. 
  It should be a decorator or something:

/**
Wraps any type that conforms to the duck interface of an associative
array to preserve ordering for iteration.
*/
struct OrderedAA(AA) {
     alias typeof(AA.init.keys.front) K;
     alias typeof(AA.init.values.front) V;
     K[] order;
     AA aa;

     void opIndexAssign(V val, K key) {
         if(!(key in aa)) {
             order ~= key;
         }

         aa[key] = val;
     }

     // opApply, etc.
}



More information about the Digitalmars-d mailing list