Skip to content

Commit

Permalink
Experiment on uncategorized data analysis
Browse files Browse the repository at this point in the history
Tried something to speed it up.  Didn't help.  Cleaned up the code
a bit though.
  • Loading branch information
fadden committed Apr 18, 2019
1 parent 61d6cd5 commit 8d0ce87
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 60 deletions.
44 changes: 43 additions & 1 deletion CommonUtil/RangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,38 @@ public bool Contains(int val) {
return (FindValue(val) >= 0);
}

#if false
/// <summary>
/// Finds a range that contains searchVal, or identifies the one that immediately
/// follows. The caller can determine which by checking to see if range.Low is
/// greater than searchVal.
/// </summary>
/// <param name="searchVal">Value to find.</param>
/// <param name="range">Result.</param>
/// <returns>True if a valid range was returned.</returns>
public bool GetContainingOrSubsequentRange(int searchVal, out Range range) {
int index = FindValue(searchVal);
if (index >= 0) {
// found a range that contains val
range = mRangeList[index];
return true;
}

// No matching range, so the index of the insertion point was returned. The
// indexed range will have a "low" value that is greater than searchVal. If
// we've reached the end of the list, the index will be past the end.
index = -index - 1;
if (index >= mRangeList.Count) {
// reached the end of the list
range = new Range(-128, -128);
return false;
}

range = mRangeList[index];
return true;
}
#endif

/// <summary>
/// Adds a value to the set. If the value is already present, nothing changes.
/// </summary>
Expand Down Expand Up @@ -352,8 +384,18 @@ public void Remove(int val) {
}


public void DebugDump(string name) {
Debug.WriteLine(name + " has " + DebugRangeCount + " ranges");
IEnumerator<Range> iter = RangeListIterator;
while (iter.MoveNext()) {
Range rng = iter.Current;
Debug.WriteLine("[+{0:x6},+{1:x6}]", rng.Low, rng.High);
}
}


/// <summary>
/// Internal test function.
/// Internal test helper function.
/// </summary>
private static bool CheckRangeSet(RangeSet set, int expectedRanges, int[] expected) {
if (set.DebugRangeCount != expectedRanges) {
Expand Down
47 changes: 46 additions & 1 deletion CommonUtil/TypedRangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,38 @@ public bool Contains(int val) {
return (FindValue(val) >= 0);
}

#if false
/// <summary>
/// Finds a range that contains searchVal, or identifies the one that immediately
/// follows. The caller can determine which by checking to see if range.Low is
/// greater than searchVal.
/// </summary>
/// <param name="searchVal">Value to find.</param>
/// <param name="range">Result.</param>
/// <returns>True if a valid range was returned.</returns>
public bool GetContainingOrSubsequentRange(int searchVal, out TypedRange range) {
int index = FindValue(searchVal);
if (index >= 0) {
// found a range that contains val
range = mRangeList[index];
return true;
}

// No matching range, so the index of the insertion point was returned. The
// indexed range will have a "low" value that is greater than searchVal. If
// we've reached the end of the list, the index will be past the end.
index = -index - 1;
if (index >= mRangeList.Count) {
// reached the end of the list
range = new TypedRange(-128, -128, -128);
return false;
}

range = mRangeList[index];
return true;
}
#endif

/// <summary>
/// Gets the type of the specified value.
/// </summary>
Expand Down Expand Up @@ -356,9 +388,12 @@ public void Add(int val, int type) {
/// </summary>
/// <param name="low">Lowest value (inclusive).</param>
/// <param name="high">Highest value (inclusive).</param>
/// <param name="high">Value type.</param>
/// <param name="type">Value type.</param>
public void AddRange(int low, int high, int type) {
// There's probably some very efficient way to do this. Keeping it simple for now.
// (TODO: do a quick check to see if there's anything overlapping; if not, just
// create a new item and insert it into the list. Should handle the common case.)
Debug.Assert(low <= high); // adding an empty set is valid but weird
for (int i = low; i <= high; i++) {
Add(i, type);
}
Expand Down Expand Up @@ -399,6 +434,16 @@ public void Remove(int val) {
}


public void DebugDump(string name) {
Debug.WriteLine(name + " has " + RangeCount + " ranges");
IEnumerator<TypedRange> iter = RangeListIterator;
while (iter.MoveNext()) {
TypedRange rng = iter.Current;
Debug.WriteLine("[+{0:x6},+{1:x6}] ({2:x2})", rng.Low, rng.High, rng.Type);
}
}


/// <summary>
/// Internal test function.
/// </summary>
Expand Down
Loading

0 comments on commit 8d0ce87

Please sign in to comment.