/** * Returns <tt>true</tt> if the receiver contains the specified value. Tests * for identity. * * @return <tt>true</tt> if the receiver contains the specified value. */ public boolean containsValue(final T value) { return !forEachPair(new LongObjectProcedure() { public boolean apply(long iterKey, Object iterValue) { return (value != iterValue); } }); }
public boolean apply(long key, Object value) { return other.containsKey(key) && other.get(key) == value; } }
/** * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result. * * @return a deep copy of the receiver. */ public AbstractLongObjectMap copy() { return (AbstractLongObjectMap) clone(); } /**
/** * Returns a list filled with all keys contained in the receiver. The * returned list has a size that equals <tt>this.size()</tt>. Iteration * order is guaranteed to be <i>identical</i> to the order used by method * {@link #forEachKey(LongProcedure)}. * <p> * This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public LongArrayList keys() { LongArrayList list = new LongArrayList(size()); keys(list); return list; }
/** * Returns a list filled with all values contained in the receiver. The * returned list has a size that equals <tt>this.size()</tt>. Iteration * order is guaranteed to be <i>identical</i> to the order used by method * {@link #forEachKey(LongProcedure)}. * <p> * This method can be used to iterate over the values of the receiver. * * @return the values. */ public ObjectArrayList<T> values() { ObjectArrayList<T> list = new ObjectArrayList<T>(size()); values(list); return list; }
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by key. */ public String toString() { LongArrayList theKeys = keys(); theKeys.sort(); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { long key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) buf.append(", "); } buf.append("]"); return buf.toString(); } /**
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by value, according to natural ordering. */ public String toStringByValue() { LongArrayList theKeys = new LongArrayList(); keysSortedByValue(theKeys); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { long key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) buf.append(", "); } buf.append("]"); return buf.toString(); } /**
if (other.size() != size()) return false; forEachPair( new LongObjectProcedure() { public boolean apply(long key, Object value) { other.forEachPair( new LongObjectProcedure() { public boolean apply(long key, Object value) {
ByteVertex(long id, AbstractLongObjectMap tx) { super(id); this.tx = tx; this.set = (SortedSet<ByteEntry>) tx.get(id); }
/** * Returns <tt>true</tt> if the receiver contains the specified key. * * @return <tt>true</tt> if the receiver contains the specified key. */ public boolean containsKey(final long key) { return !forEachKey(new LongProcedure() { public boolean apply(long iterKey) { return (key != iterKey); } }); }
/** * Fills all keys <i>sorted ascending by their associated value</i> into the specified list. * Fills into the list, starting at index 0. * After this call returns the specified list has a new size that equals <tt>this.size()</tt>. * Primary sort criterium is "value", secondary sort criterium is "key". * This means that if any two values are equal, the smaller key comes first. * <p> * <b>Example:</b> * <br> * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (8,6,7)</tt> * * @param keyList the list to be filled, can have any size. */ public void keysSortedByValue(final LongArrayList keyList) { pairsSortedByValue(keyList, new ObjectArrayList(size())); } /**
final AbstractLongObjectMap map = new OpenLongObjectHashMap(size); for (int i = 1; i <= size; i++) { map.put(size, "O" + i); map.forEachPair(new LongObjectProcedure() { @Override public boolean apply(long l, Object o) {
private static long testByte() { AbstractLongObjectMap tx = new OpenLongObjectHashMap(NUM); for (int i = 0; i < NUM; i++) { tx.put(i, new ConcurrentSkipListSet<ByteEntry>()); } for (int i = 0; i < NUM; i++) { for (int j = 0; j < NUM; j++) { if (i == j) continue; if (Math.random() < FRACTION) { ByteBuffer key = ByteBuffer.allocate(16); key.putLong(5).putLong(j).flip(); ByteBuffer value = ByteBuffer.allocate(4); value.putInt(random.nextInt(ROUNDSIZE)).flip(); ((ConcurrentSkipListSet<ByteEntry>) tx.get(i)).add(new ByteEntry(key, value)); } } } long time = System.currentTimeMillis(); long sum = 0; for (int t = 0; t < TRIALS; t++) { for (int i = 0; i < NUM; i++) { for (Vertex v : (new ByteVertex(i, tx)).getNeighbors(0)) { sum += v.getId(); } } } time = System.currentTimeMillis() - time; return time; }
super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity==0) capacity=1; // open addressing needs at least one FREE slot at any time.
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by key. */ public String toString() { LongArrayList theKeys = keys(); theKeys.sort(); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { long key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) buf.append(", "); } buf.append("]"); return buf.toString(); } /**
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by value, according to natural ordering. */ public String toStringByValue() { LongArrayList theKeys = new LongArrayList(); keysSortedByValue(theKeys); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { long key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) buf.append(", "); } buf.append("]"); return buf.toString(); } /**
return false; final AbstractLongObjectMap other = (AbstractLongObjectMap) obj; if (other.size() != size()) return false; return forEachPair(new LongObjectProcedure() { public boolean apply(long key, Object value) { return other.containsKey(key) && other.get(key) == value; }) && other.forEachPair(new LongObjectProcedure() { public boolean apply(long key, Object value) { return containsKey(key) && get(key) == value;
public boolean apply(long key) { list.add(get(key)); return true; } }
/** * Returns <tt>true</tt> if the receiver contains the specified key. * * @return <tt>true</tt> if the receiver contains the specified key. */ public boolean containsKey(final long key) { return ! forEachKey( new LongProcedure() { public boolean apply(long iterKey) { return (key != iterKey); } } ); } /**