On 11/11/2013 05:14 PM, bioinfornatics wrote:
Dear,
I am looking for a bidirectional map i.e
http://en.wikipedia.org/wiki/Bidirectional_map

My seach into D documentation seem to said to me that this structure is
not implemented.

Something like (for primary idea):


struct BidirectionalMap(T,U){
     private:
         T[U] _forwardHash;
         U[T] _reverseHash;

     public:

         @safe
         void opIndeyAssign( T k, U v){ // pure?
             _forwardHash[k] = v;
             _reverseHash[v] = k;
         }


         @property
         BidirectionalMap!(T,U) dup(){
             return BidirectionalMap!(T,U)( this );
         }
}

you could build one using multi_index.

https://bitbucket.org/ariovistus/multi_index

at least, that is how boost::bimap was done. I always assumed it would be trivial in D, but I haven't tried doing it. Something like

alias MultiIndexContainer!(Tuple!(T,"t",U,"u"), IndexedBy!(HashedUnique!("a.t"), HashedUnique!("a.u"))) BiMap;

and then wrap as you see fit.

Reply via email to