Ejemplo n.º 1
0
 public synchronized int remove(int key) {
   IntLinkedSetry buk[] = table;
   int index = hash(key) % buk.length;
   for (IntLinkedSetry e = buk[index], prev = null; e != null; prev = e, e = e.next) {
     if (CompareUtil.equals(e.key, key)) {
       if (prev != null) {
         prev.next = e.next;
       } else {
         buk[index] = e.next;
       }
       count--;
       //
       unchain(e);
       return key;
     }
   }
   return NONE;
 }
Ejemplo n.º 2
0
 private synchronized int _put(int key, MODE m) {
   IntLinkedSetry buk[] = table;
   int index = hash(key) % buk.length;
   for (IntLinkedSetry e = buk[index]; e != null; e = e.next) {
     if (CompareUtil.equals(e.key, key)) {
       switch (m) {
         case FORCE_FIRST:
           if (header.link_next != e) {
             unchain(e);
             chain(header, header.link_next, e);
           }
           break;
         case FORCE_LAST:
           if (header.link_prev != e) {
             unchain(e);
             chain(header.link_prev, header, e);
           }
           break;
       }
       return key;
     }
   }
   if (max > 0) {
     switch (m) {
       case FORCE_FIRST:
       case FIRST:
         while (count >= max) {
           int v = header.link_prev.key;
           remove(v);
           overflowed(v);
         }
         break;
       case FORCE_LAST:
       case LAST:
         while (count >= max) {
           int v = header.link_next.key;
           remove(v);
           overflowed(v);
         }
         break;
     }
   }
   if (count >= threshold) {
     rehash();
     buk = table;
     index = hash(key) % buk.length;
   }
   IntLinkedSetry e = new IntLinkedSetry(key, buk[index]);
   buk[index] = e;
   switch (m) {
     case FORCE_FIRST:
     case FIRST:
       chain(header, header.link_next, e);
       break;
     case FORCE_LAST:
     case LAST:
       chain(header.link_prev, header, e);
       break;
   }
   count++;
   return NONE;
 }