public long putLast(String key, long value) { return _put(key, value, MODE.FORCE_LAST); } public long putFirst(String key, long value) {
protected void rehash() { int oldCapacity = table.length; StringLongLinkedEntry oldMap[] = table; int newCapacity = oldCapacity * 2 + 1; StringLongLinkedEntry newMap[] = new StringLongLinkedEntry[newCapacity]; threshold = (int) (newCapacity * loadFactor); table = newMap; for (int i = oldCapacity; i-- > 0;) { StringLongLinkedEntry old = oldMap[i]; while(old!=null) { StringLongLinkedEntry e = old; old = old.next; String key = e.key; int index = hash(key) % newCapacity; e.next = newMap[index]; newMap[index] = e; } } } private int max;
int index = hash(key) % tab.length; for (StringLongLinkedEntry 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: chain(header.link_prev, header, e);
public String toFormatString() { StringBuffer buf = new StringBuffer(); Enumeration it = entries(); buf.append("{\n"); while(it.hasMoreElements()){ StringLongLinkedEntry e = (StringLongLinkedEntry)it.nextElement(); buf.append("\t").append(e.getKey() + "=" + e.getValue()).append("\n"); } buf.append("}"); return buf.toString(); } public static class StringLongLinkedEntry {
public synchronized long remove(String key) { if(key==null) return NONE; StringLongLinkedEntry tab[] = table; int index = hash(key) % tab.length; for (StringLongLinkedEntry 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 synchronized long removeFirst() {
public synchronized long getLastValue() { if (isEmpty()) return NONE; return this.header.link_prev.value; } private int hash(String key) {
public boolean isEmpty() { return size() == 0; } public synchronized void clear() {
int index = hash(key) % tab.length; for (StringLongLinkedEntry 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: chain(header.link_prev, header, e);
public String toFormatString() { StringBuffer buf = new StringBuffer(); Enumeration it = entries(); buf.append("{\n"); while(it.hasMoreElements()){ StringLongLinkedEntry e = (StringLongLinkedEntry)it.nextElement(); buf.append("\t").append(e.getKey() + "=" + e.getValue()).append("\n"); } buf.append("}"); return buf.toString(); } public static class StringLongLinkedEntry {
public synchronized long remove(String key) { if(key==null) return NONE; StringLongLinkedEntry tab[] = table; int index = hash(key) % tab.length; for (StringLongLinkedEntry 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 synchronized long removeFirst() {
public synchronized long getFirsValue() { if (isEmpty()) return NONE; return this.header.link_next.value; } public synchronized long getLastValue() {
public boolean isEmpty() { return size() == 0; } public synchronized void clear() {
int index = hash(key) % tab.length; for (StringLongLinkedEntry 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: chain(header.link_prev, header, e);
public long put(String key, long value) { return _put(key, value, MODE.LAST); } public long putLast(String key, long value) {
public String toFormatString() { StringBuffer buf = new StringBuffer(); Enumeration it = entries(); buf.append("{\n"); while(it.hasMoreElements()){ StringLongLinkedEntry e = (StringLongLinkedEntry)it.nextElement(); buf.append("\t").append(e.getKey() + "=" + e.getValue()).append("\n"); } buf.append("}"); return buf.toString(); } public static class StringLongLinkedEntry {