Skip to content

Commit

Permalink
Fix matrix connection update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashuber-lawo committed Apr 18, 2017
1 parent 0cee985 commit 1d38bfd
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Lawo.EmberPlusSharp/Model/MatrixBase`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,15 @@ private static int GetMaximumTotalConnects(MatrixType type, int targetCount, int
private static void Insert(ObservableCollection<int> existingSources, int[] sources, bool replace)
{
Array.Sort(sources);
int index = 0;

foreach (var source in sources)
if (replace)
{
int? existingSource = null;
// Remove all elements in existingSources not contained in sources
var index = 0;

while ((index < existingSources.Count) && ((existingSource = existingSources[index]) < source))
while (index < existingSources.Count)
{
if (replace)
if (Array.BinarySearch(sources, existingSources[index]) < 0)
{
existingSources.RemoveAt(index);
}
Expand All @@ -343,13 +343,24 @@ private static void Insert(ObservableCollection<int> existingSources, int[] sour
++index;
}
}
}

// Insert sources elements into existingSources, but skip elements already present in existingSources
var insertIndex = 0;

foreach (var source in sources)
{
int? existingSource = null;

if (existingSource != source)
while ((insertIndex < existingSources.Count) && ((existingSource = existingSources[insertIndex]) < source))
{
existingSources.Insert(index, source);
++insertIndex;
}

++index;
if (source != existingSource)
{
existingSources.Insert(insertIndex, source);
}
}
}

Expand Down

0 comments on commit 1d38bfd

Please sign in to comment.