I am developing using an electric calculation engine where all the objects are of the type WDataObject.
I have a class to create graphs that works fine with string values, but now I need to create a graph of these WDataObjects.
to see if a WDataObject is equal to other WDataObject I have to use the own method: .isEqual(WDataObject obj)
therefore, if I create a dictionary like
Dictionary<WDataObject , LinkedList<WDataObject>> map = new Dictionary<WDataObject , LinkedList<WDataObject>>( );
I cannot obtain the Values from the keys normally, instead I have to create iterators and manually check the equivalency.
I have this function that works fine:
public void addOneWayRelation ( string node1 , string node2 ) {
LinkedList<string> adjacent = new LinkedList<string>( );
try {
adjacent = map[node1];
} catch ( System.Collections.Generic.KeyNotFoundException ) {
map[node1] = adjacent;
}
adjacent.AddLast( node2 );
}
And I need to change the types from string to WDataObject.
I already have the key search
private LinkedList<WDataObject> searchKey ( WDataObject k ) {
List<WDataObject> Keys = new List<WDataObject>( map.Keys );
List<LinkedList<WDataObject>> Values = new List<LinkedList<WDataObject>>( map.Values );
for ( int i = 0 ; i < Keys.Count ; i++ ) {
if ( Keys[i].IsEqual( k ) ) {
return Values[i];
}
}
return null;
}
The problem is
map[node1] = adjacent;
How do i replace a Value from an specific key in this context?
Any help is appreciated.