예제 #1
0
파일: Queue.java 프로젝트: ablochha/Resume
 /**
  * Adds the item to this queue.
  *
  * @param item the item to add
  */
 public void enqueue(Item item) {
   Node<Item> oldlast = last;
   last = new Node<Item>();
   last.item = item;
   last.next = null;
   if (isEmpty()) first = last;
   else oldlast.next = last;
   N++;
 }
 public V put(K key, V value) {
   if (table == null || table.length == 0) {
     table = resize();
   }
   Node<K, V> p;
   int n = table.length, i, hash = hash(key);
   if ((p = table[i = (n - 1) & hash]) == null) {
     table[i] = new Node<>(hash, key, value, null);
   } else {
     while (true) {
       if (p.hash == hash && Objects.equals(p.key, key)) {
         V oldVal = p.value;
         p.value = value;
         return oldVal;
       }
       if (p.next == null) {
         break;
       }
       p = p.next;
     }
     p.next = new Node<>(hash, key, value, null);
   }
   if (++size == n) {
     table = resize();
   }
   return null;
 }