Ejemplo n.º 1
0
  private static Entry[] merge(LinkedList<Entry> childEntries, VTable parent) {
    if (parent == null) {
      return childEntries.toArray(new Entry[childEntries.size()]);
    }
    ArrayList<Entry> result = new ArrayList<Entry>();
    outer:
    for (Entry entryParent : parent.entries) {
      for (Iterator<Entry> it = childEntries.iterator(); it.hasNext(); ) {
        Entry entryChild = it.next();
        if (entryChild.overrides(entryParent)) {
          entryChild.index = entryParent.index;
          result.add(entryChild);
          it.remove();
          continue outer;
        }
      }
      // No overriding entry found. Use the parent one.
      result.add(entryParent);
    }

    // result now contains entries from the parent with overrides. Left in childEntries are
    // those which don't override anything in the parent. Just append to the back and make sure
    // the indexes are correct.
    for (Entry entry : childEntries) {
      entry.index = result.size();
      result.add(entry);
    }

    return result.toArray(new Entry[result.size()]);
  }
 /**
  * Structural swap of two entries.
  *
  * @param entryA
  * @param entryB
  */
 private void swap(Entry<E> entryA, Entry<E> entryB) {
   int indexA = entryA.index;
   int indexB = entryB.index;
   entryA.index = indexB;
   entryB.index = indexA;
   indexToEntry.set(indexA, entryB);
   indexToEntry.set(indexB, entryA);
 }
 private Entry<E> makeEntry(E key) {
   Entry<E> entry = new Entry<E>();
   entry.index = size();
   entry.key = key;
   entry.priority = Double.NEGATIVE_INFINITY;
   indexToEntry.add(entry);
   keyToEntry.put(key, entry);
   return entry;
 }
Ejemplo n.º 4
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.acceleo.common.utils.CompactHashSet#rehash(int)
   */
  @SuppressWarnings("unchecked")
  @Override
  protected void rehash(int newCapacity) {
    final int mask = newCapacity - 1;
    final E[] temp = (E[]) new Object[newCapacity];

    for (Entry entry = header.next; entry != header; entry = entry.next) {
      E value = data[entry.index];
      final int hash = supplementalHash(value.hashCode());
      int insertionIndex = hash & mask;

      while (temp[insertionIndex] != null) {
        insertionIndex = (insertionIndex + 1) & mask;
      }

      entry.index = insertionIndex;
      temp[insertionIndex] = value;
    }

    data = temp;
    threshold = (int) (newCapacity * loadFactor);
  }