Sorted GapList

17 views
Skip to first unread message

hell...@googlemail.com

unread,
Apr 14, 2017, 11:30:47 AM4/14/17
to brownies-collections
Hi,

is it possible to have a sorted GapList by using gaplist.binarySearch? I've tested it but it seems it isn't ordered correctly. I'm using this code to find an insertion position:

public int compare(KeyEntry o1, KeyEntry o2) {
return o1.storeTime==o2.storeTime?0:o1.storeTime<o2.storeTime?-1:1;
}

private int findIndex(KeyEntry entry) {
if (entryList.size() == 0)
return 0;
int idx = entryList.binarySearch(entry, this);
return idx < 0?0:idx;
}

Thanks,
Andreas

hell...@googlemail.com

unread,
Apr 15, 2017, 3:59:20 AM4/15/17
to brownies-collections
Already found an issue in my insertion point. Must be -(idx+1) if < 0.

Thomas Mauch

unread,
Apr 16, 2017, 3:54:15 AM4/16/17
to brownies-collections
Hi Andreas

I hope it works now.
Basically GapList should behave like ArrayList.

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages