/** * Find the index of the entry nearest the given index, starting in the * given direction. */ private int findEntry(int start, boolean forward, boolean searchedOther) { if (forward) { for (int i = start; i < table.length; i++) if (table[i] != null) return i; return (searchedOther || start == 0) ? -1 : findEntry(start - 1, false, true); } else { for (int i = start; i >= 0; i--) if (table[i] != null) return i; return (searchedOther || start == table.length - 1) ? -1 : findEntry(start + 1, true, true); } }
/** * Find the index of the entry nearest the given index, starting in the * given direction. */ private int findEntry(int start, boolean forward, boolean searchedOther) { if (forward) { for (int i = start; i < table.length; i++) if (table[i] != null) return i; return (searchedOther || start == 0) ? -1 : findEntry(start - 1, false, true); } else { for (int i = start; i >= 0; i--) if (table[i] != null) return i; return (searchedOther || start == table.length - 1) ? -1 : findEntry(start + 1, true, true); } }
/** * Find the index of the entry nearest the given index, starting in the * given direction. */ private int findEntry(int start, boolean forward, boolean searchedOther) { if (forward) { for (int i = start; i < table.length; i++) if (table[i] != null) return i; return (searchedOther || start == 0) ? -1 : findEntry(start - 1, false, true); } else { for (int i = start; i >= 0; i--) if (table[i] != null) return i; return (searchedOther || start == table.length - 1) ? -1 : findEntry(start + 1, true, true); } }
/** * Find the index of the entry nearest the given index, starting in the * given direction. */ private int findEntry(int start, boolean forward, boolean searchedOther) { if (forward) { for (int i = start; i < table.length; i++) if (table[i] != null) return i; return (searchedOther || start == 0) ? -1 : findEntry(start - 1, false, true); } else { for (int i = start; i >= 0; i--) if (table[i] != null) return i; return (searchedOther || start == table.length - 1) ? -1 : findEntry(start + 1, true, true); } }
public Map.Entry removeRandom() { synchronized (this) { expungeStaleEntries(); if (count == 0) return null; int random = randomEntryIndex(); int index = findEntry(random, random % 2 == 0, false); if (index == -1) return null; Entry rem = table[index]; table[index] = rem.getNext(); count--; return rem; } }
public Map.Entry removeRandom() { synchronized (this) { expungeStaleEntries(); if (count == 0) return null; int random = randomEntryIndex(); int index = findEntry(random, random % 2 == 0, false); if (index == -1) return null; Entry rem = table[index]; table[index] = rem.getNext(); count--; return rem; } }
public Map.Entry removeRandom() { synchronized (this) { expungeStaleEntries(); if (count == 0) return null; int random = randomEntryIndex(); int index = findEntry(random, random % 2 == 0, false); if (index == -1) return null; Entry rem = table[index]; table[index] = rem.getNext(); count--; return rem; } }
public Map.Entry removeRandom() { synchronized (this) { expungeStaleEntries(); if (count == 0) return null; int random = randomEntryIndex(); int index = findEntry(random, random % 2 == 0, false); if (index == -1) return null; Entry rem = table[index]; table[index] = rem.getNext(); count--; return rem; } }