HBASE-18251 Remove unnecessary traversing to the first and last keys in
the CellSet (Toshihoro Suzuki)
This commit is contained in:
parent
b0878184a3
commit
9da4e6906e
|
@ -282,37 +282,85 @@ public abstract class CellFlatMap implements NavigableMap<Cell,Cell> {
|
|||
}
|
||||
|
||||
// -------------------------------- Entry's getters --------------------------------
|
||||
// all interfaces returning Entries are unsupported because we are dealing only with the keys
|
||||
|
||||
private static class CellFlatMapEntry implements Entry<Cell, Cell> {
|
||||
private final Cell cell;
|
||||
|
||||
public CellFlatMapEntry (Cell cell) {
|
||||
this.cell = cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cell getKey() {
|
||||
return cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cell getValue() {
|
||||
return cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cell setValue(Cell value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<Cell, Cell> lowerEntry(Cell k) {
|
||||
throw new UnsupportedOperationException();
|
||||
Cell cell = lowerKey(k);
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
return new CellFlatMapEntry(cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<Cell, Cell> higherEntry(Cell k) {
|
||||
throw new UnsupportedOperationException();
|
||||
Cell cell = higherKey(k);
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
return new CellFlatMapEntry(cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<Cell, Cell> ceilingEntry(Cell k) {
|
||||
throw new UnsupportedOperationException();
|
||||
Cell cell = ceilingKey(k);
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
return new CellFlatMapEntry(cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<Cell, Cell> floorEntry(Cell k) {
|
||||
throw new UnsupportedOperationException();
|
||||
Cell cell = floorKey(k);
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
return new CellFlatMapEntry(cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<Cell, Cell> firstEntry() {
|
||||
throw new UnsupportedOperationException();
|
||||
Cell cell = firstKey();
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
return new CellFlatMapEntry(cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<Cell, Cell> lastEntry() {
|
||||
throw new UnsupportedOperationException();
|
||||
Cell cell = lastKey();
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
return new CellFlatMapEntry(cell);
|
||||
}
|
||||
|
||||
// The following 2 methods (pollFirstEntry, pollLastEntry) are unsupported because these are updating methods.
|
||||
@Override
|
||||
public Entry<Cell, Cell> pollFirstEntry() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -323,7 +371,6 @@ public abstract class CellFlatMap implements NavigableMap<Cell,Cell> {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------- Updates --------------------------------
|
||||
// All updating methods below are unsupported.
|
||||
// Assuming an array of Cells will be allocated externally,
|
||||
|
|
|
@ -126,15 +126,12 @@ public class CellSet implements NavigableSet<Cell> {
|
|||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
// TODO: why do we have a double traversing through map? Recall we have Cell to Cell mapping...
|
||||
// First for first/last key, which actually returns Cell and then get for the same Cell?
|
||||
// TODO: Consider just return the first/lastKey(), should be twice more effective...
|
||||
public Cell first() {
|
||||
return this.delegatee.get(this.delegatee.firstKey());
|
||||
return this.delegatee.firstEntry().getValue();
|
||||
}
|
||||
|
||||
public Cell last() {
|
||||
return this.delegatee.get(this.delegatee.lastKey());
|
||||
return this.delegatee.lastEntry().getValue();
|
||||
}
|
||||
|
||||
public boolean add(Cell e) {
|
||||
|
|
Loading…
Reference in New Issue