1 module des.math.graph.base; 2 3 struct WTable(T) 4 { 5 private: 6 T[] data; 7 size_t _width; 8 9 public: 10 11 this( size_t sz, T init_value=T.init ) 12 { 13 _width = sz; 14 data.length = sz * sz; 15 data[] = init_value; 16 } 17 18 size_t size() pure const @property { return _width; } 19 20 T opIndex( size_t from, size_t to ) const pure 21 { return data[ from*size + to ]; } 22 23 ref T opIndex( size_t from, size_t to ) pure 24 { return data[ from*size + to ]; } 25 26 int opApply( int delegate(size_t, size_t, T) dlg ) const 27 { 28 foreach( i, w; data ) 29 if( auto r = dlg( i/size, i%size, w ) ) 30 return r; 31 return 0; 32 } 33 34 int opApply( int delegate(size_t, size_t, ref T) dlg ) 35 { 36 foreach( i, ref w; data ) 37 if( auto r = dlg( i/size, i%size, w ) ) 38 return r; 39 return 0; 40 } 41 } 42 43 struct Path(T) 44 { 45 T cost; 46 size_t[] nodes; 47 }