c# - How to check if dictionary contains a value in a generic list -


i have list of coordinates stored in generic list. want able iterate through list , check if coordinates adjacent each other. if are, know same groups versus if aren't. know how properly?

update: here's updated code far. grouping coordinates in new generic list , adding them dictionary if adjacent , same type.

now want know if dictionary contains coordinate in group. doesn't run same process again. how access values of generic list in dictionary?

    private void groupmatchtile(list<int[]> matchtile){         int = 0;         dictionary<int, list<int[]>> groups = new dictionary<int, list<int[]>>();          foreach(int[] coord in matchtile){             if(groups.containsvalue(              // how check if coords belong in group              )) return;              groups.add(i, new list<int[]>());                groups[i].add(coord);              foreach(int[] nextcoord in matchtile){                 if (coord == nextcoord) return;                 else {                     if (    isadjacent(coord[0], coord[1], nextcoord[0], nextcoord[1]) &&                             level.grid[coord[0], coord[1]] == level.grid[nextcoord[0], nextcoord[1]]                     ){                         groups[i].add(nextcoord);                        }                 }             }              i++;         }        } 

you want better data structure avoid o(n^2) search. maybe 2d array? work required construct out of current list might worth it.

you need track group id each point. because isadjacent function not give transitivity i.e. if 3 points differ 1 unit in x direction only, want them in same group isadjacent (p1, p3) false.

then logic

if (isadjacent (point1, point2)) {     point1.groupid = point2.groupid = min (point1.groupid, point2.groupid) } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -