Skip to content

Commit

Permalink
Fixed searching algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Apr 5, 2015
1 parent d9ae5fa commit 809b44c
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions MPChartLib/src/com/github/mikephil/charting/data/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public T getEntryForXIndex(int x) {
int m = (high + low) / 2;

if (x == mYVals.get(m).getXIndex()) {
while (m > 0 && mYVals.get(m - 1).getXIndex() == x)
m--;

return mYVals.get(m);
}

Expand Down Expand Up @@ -211,16 +214,32 @@ public List<T> getEntriesForXIndex(int x) {
List<T> entries = new ArrayList<T>();

int low = 0;
int high = mYVals.size();
int high = mYVals.size() - 1;

while (low <= high) {
int m = (high + low) / 2;

if (x == mYVals.get(m).getXIndex()) {
entries.add(mYVals.get(m));
T entry = mYVals.get(m);

if (x == entry.getXIndex()) {
while (m > 0 && mYVals.get(m - 1).getXIndex() == x)
m--;

high = mYVals.size();
for (; m < high; m++)
{
entry = mYVals.get(m);
if (entry.getXIndex() == x)
{
entries.add(entry);
}
else
{
break;
}
}
}

if (x > mYVals.get(m).getXIndex())
if (x > entry.getXIndex())
low = m + 1;
else
high = m - 1;
Expand Down

0 comments on commit 809b44c

Please sign in to comment.