Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster size on stable tables. #346

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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