public long put(long key, long value) { return _put(key, value, MODE.LAST); }
private synchronized long _put(long key, long value, MODE m) { LongLongLinkedEntry tab[] = table; int index = hash(key) % tab.length; for (LongLongLinkedEntry e = tab[index]; e != null; e = e.next) { if (CompareUtil.equals(e.key, key)) { case FORCE_FIRST: if (header.link_next != e) { unchain(e); chain(header, header.link_next, e); unchain(e); chain(header.link_prev, header, e); long v = remove(k); overflowed(k, v); long v = remove(k); overflowed(k, v); rehash(); tab = table; index = hash(key) % tab.length; case FORCE_FIRST: case FIRST: chain(header, header.link_next, e); break; case FORCE_LAST: case LAST:
public synchronized long remove(long key) { LongLongLinkedEntry tab[] = table; int index = hash(key) % tab.length; for (LongLongLinkedEntry e = tab[index], prev = null; e != null; prev = e, e = e.next) { if (CompareUtil.equals(e.key, key)) { if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } count--; long oldValue = e.value; e.value = NONE; // unchain(e); return oldValue; } } return NONE; }
public static void main(String[] args) { LongLongLinkedMap m = new LongLongLinkedMap(); // m.put(1, 1); // m.put(2, 1); // m.put(3, 1); // m.put(4, 1); // LongEnumer e = m.keys(); System.out.println(e.nextLong()); System.out.println(e.nextLong()); System.out.println(e.nextLong()); System.out.println(e.nextLong()); // System.out.println(e.nextLong()); }
public String toFormatString() { StringBuffer buf = new StringBuffer(); Enumeration it = entries(); buf.append("{\n"); while (it.hasMoreElements()) { LongLongLinkedEntry e = (LongLongLinkedEntry) it.nextElement(); buf.append("\t").append(e.getKey() + "=" + e.getValue()).append("\n"); } buf.append("}"); return buf.toString(); }
protected void rehash() { int oldCapacity = table.length; LongLongLinkedEntry oldMap[] = table; int newCapacity = oldCapacity * 2 + 1; LongLongLinkedEntry newMap[] = new LongLongLinkedEntry[newCapacity]; threshold = (int) (newCapacity * loadFactor); table = newMap; for (int i = oldCapacity; i-- > 0;) { LongLongLinkedEntry old = oldMap[i]; while (old != null) { LongLongLinkedEntry e = old; old = old.next; long key = e.key; int index = hash(key) % newCapacity; e.next = newMap[index]; newMap[index] = e; } } }
public synchronized static int getUsers() { long max_think_time=Configure.getInstance().counter_recentuser_valid_ms; int v = 0; long now = System.currentTimeMillis(); try { Enumeration<LongLongLinkedEntry> en = users.entries(); while (en.hasMoreElements()) { LongLongLinkedEntry e = en.nextElement(); if (now - e.getValue() >max_think_time) { users.remove(e.getKey()); } else { v++; } } } catch (Throwable t) { Logger.println("A114", "METER-USERS" + t.toString()); } return v; }
public static void main(String[] args) { LongLongLinkedMap m = new LongLongLinkedMap(); // m.put(1, 1); // m.put(2, 1); // m.put(3, 1); // m.put(4, 1); // LongEnumer e = m.keys(); System.out.println(e.nextLong()); System.out.println(e.nextLong()); System.out.println(e.nextLong()); System.out.println(e.nextLong()); // System.out.println(e.nextLong()); }
public synchronized long remove(long key) { LongLongLinkedEntry tab[] = table; int index = hash(key) % tab.length; for (LongLongLinkedEntry e = tab[index], prev = null; e != null; prev = e, e = e.next) { if (CompareUtil.equals(e.key, key)) { if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } count--; long oldValue = e.value; e.value = NONE; // unchain(e); return oldValue; } } return NONE; }
public String toFormatString() { StringBuffer buf = new StringBuffer(); Enumeration it = entries(); buf.append("{\n"); while (it.hasMoreElements()) { LongLongLinkedEntry e = (LongLongLinkedEntry) it.nextElement(); buf.append("\t").append(e.getKey() + "=" + e.getValue()).append("\n"); } buf.append("}"); return buf.toString(); }
protected void rehash() { int oldCapacity = table.length; LongLongLinkedEntry oldMap[] = table; int newCapacity = oldCapacity * 2 + 1; LongLongLinkedEntry newMap[] = new LongLongLinkedEntry[newCapacity]; threshold = (int) (newCapacity * loadFactor); table = newMap; for (int i = oldCapacity; i-- > 0;) { LongLongLinkedEntry old = oldMap[i]; while (old != null) { LongLongLinkedEntry e = old; old = old.next; long key = e.key; int index = hash(key) % newCapacity; e.next = newMap[index]; newMap[index] = e; } } }
public synchronized static int getUsers() { long max_think_time=Configure.getInstance().counter_recentuser_valid_ms; int v = 0; long now = System.currentTimeMillis(); try { Enumeration<LongLongLinkedEntry> en = users.entries(); while (en.hasMoreElements()) { LongLongLinkedEntry e = en.nextElement(); if (now - e.getValue() >max_think_time) { users.remove(e.getKey()); } else { v++; } } } catch (Throwable t) { Logger.println("A114", "METER-USERS" + t.toString()); } return v; }
private synchronized long _put(long key, long value, MODE m) { LongLongLinkedEntry tab[] = table; int index = hash(key) % tab.length; for (LongLongLinkedEntry e = tab[index]; e != null; e = e.next) { if (CompareUtil.equals(e.key, key)) { case FORCE_FIRST: if (header.link_next != e) { unchain(e); chain(header, header.link_next, e); unchain(e); chain(header.link_prev, header, e); long v = remove(k); overflowed(k, v); long v = remove(k); overflowed(k, v); rehash(); tab = table; index = hash(key) % tab.length; case FORCE_FIRST: case FIRST: chain(header, header.link_next, e); break; case FORCE_LAST: case LAST:
public static void main(String[] args) { LongLongLinkedMap m = new LongLongLinkedMap(); // m.put(1, 1); // m.put(2, 1); // m.put(3, 1); // m.put(4, 1); // LongEnumer e = m.keys(); System.out.println(e.nextLong()); System.out.println(e.nextLong()); System.out.println(e.nextLong()); System.out.println(e.nextLong()); // System.out.println(e.nextLong()); }
public long put(long key, long value) { return _put(key, value, MODE.LAST); }