Skip to content

Commit

Permalink
Faster size on stable tables.
Browse files Browse the repository at this point in the history
Faster iteration on stable tables.
  • Loading branch information
cliffclick committed Apr 2, 2021
1 parent 66e6cbc commit e5231be
Showing 1 changed file with 18 additions and 0 deletions.
Expand Up @@ -256,6 +256,8 @@ private void initialize( final int initial_sz ) {
/** Returns the number of key-value mappings in this map.
* @return the number of key-value mappings in this map */
public int size ( ) { return (_val_1==TOMBSTONE?0:1) + _chm.size(); }
/** Faster size (and exact) call on a stable table; returns a fast decent estimate on a moving table */
public int estimate_size() { return (_val_1==TOMBSTONE?0:1) + _chm.estimate_size(); }
/** Tests if the key in the table.
* @return <tt>true</tt> if the key is in the table */
public boolean containsKey( long key ) { return get(key) != null; }
Expand Down Expand Up @@ -433,6 +435,7 @@ private static final class CHM implements Serializable {
// Size in active K,V pairs
private ConcurrentAutoTable _size;
public int size () { return (int)_size.get(); }
public int estimate_size () { return (int)_size.estimate_get(); }

// ---
// These next 2 fields are used in the resizing heuristics, to judge when
Expand Down Expand Up @@ -1188,6 +1191,21 @@ public long[] keySetLong() {
return dom;
}

/** Raw underlying array of longs as keys. Faster iterator if the table is
* stable. 0 represents a missing key. Changes to the NBHML may change
* this table. Modifications to the table outside of the NBHML API will
* probably break the table. */
public long[] rawKeySet() {
while( true ) { // Verify no table-copy-in-progress
CHM topchm = _chm;
if( topchm._newchm == null ) // No table-copy-in-progress
return topchm._keys;
// Table copy in-progress - so we cannot get a clean iteration. We
// must help finish the table copy before we can start iterating.
topchm.help_copy_impl(true);
}
}

// --- entrySet ------------------------------------------------------------
// Warning: Each call to 'next' in this iterator constructs a new Long and a
// new NBHMLEntry.
Expand Down

0 comments on commit e5231be

Please sign in to comment.