本文整理汇总了Java中gnu.trove.map.TIntLongMap类的典型用法代码示例。如果您正苦于以下问题:Java TIntLongMap类的具体用法?Java TIntLongMap怎么用?Java TIntLongMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TIntLongMap类属于gnu.trove.map包,在下文中一共展示了TIntLongMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TIntLongHashMap
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
/**
* Creates a new <code>TIntLongHashMap</code> instance containing
* all of the entries in the map passed in.
*
* @param map a <tt>TIntLongMap</tt> that will be duplicated.
*/
public TIntLongHashMap( TIntLongMap map ) {
super( map.size() );
if ( map instanceof TIntLongHashMap ) {
TIntLongHashMap hashmap = ( TIntLongHashMap ) map;
this._loadFactor = hashmap._loadFactor;
this.no_entry_key = hashmap.no_entry_key;
this.no_entry_value = hashmap.no_entry_value;
//noinspection RedundantCast
if ( this.no_entry_key != ( int ) 0 ) {
Arrays.fill( _set, this.no_entry_key );
}
//noinspection RedundantCast
if ( this.no_entry_value != ( long ) 0 ) {
Arrays.fill( _values, this.no_entry_value );
}
setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) );
}
putAll( map );
}
示例2: testRehash
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
/** Be sure that size is large enough to force a resize or two. */
public void testRehash() {
int size = 1000;
int[] keys = new int[size];
long[] vals = new long[size];
for ( int i = 0; i < size; i++ ) {
keys[i] = i + 1;
vals[i] = keys[i] * 2;
}
TIntLongMap map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
map.put( keys[i], vals[i] );
}
assertEquals( keys.length, map.size() );
for ( int i = 0; i < keys.length; i++ ) {
int key = keys[i];
long val = vals[i];
assertEquals( "got incorrect value for index " + i + ", map: " + map,
val, map.get( key ) );
}
}
示例3: testClear
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testClear() {
int[] keys = {1138, 42, 86, 99, 101};
long[] vals = {1138, 42, 86, 99, 101};
TIntLongMap map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
map.put( keys[i], vals[i] * 2 );
}
assertEquals( keys.length, map.size() );
map.clear();
assertEquals( 0, map.size() );
assertTrue( map.isEmpty() );
TIntLongMap empty = new TIntLongHashMap();
assertEquals( empty, map );
// Map<String,String> jmap = new HashMap<String, String>();
// jmap.isEmpty()
}
示例4: testBug2037709
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testBug2037709() {
TIntLongMap m = new TIntLongHashMap();
for ( int i = 0; i < 10; i++ ) {
m.put( i, i );
}
int sz = m.size();
assertEquals( 10, sz );
int[] keys = new int[sz];
m.keys( keys );
boolean[] seen = new boolean[sz];
Arrays.fill( seen, false );
for ( int i = 0; i < 10; i++ ) {
seen[keys[i]] = true;
}
for ( int i = 0; i < 10; i++ ) {
if ( !seen[i] ) {
TestCase.fail( "Missing key for: " + i );
}
}
}
示例5: testTransformValues
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testTransformValues() {
int element_count = 20;
TIntLongMap map = new TIntLongHashMap();
for ( int i = 1; i <= element_count; i++ ) {
map.put( i, i );
}
class TransformValues implements TLongFunction {
@Override
public long execute( long value ) {
return value * value;
}
}
TransformValues foreach = new TransformValues();
map.transformValues( foreach );
for ( int i = 1; i <= element_count; i++ ) {
assertEquals( i * i, map.get( i ) );
}
}
示例6: testIncrement
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testIncrement() {
int element_count = 20;
TIntLongMap map = new TIntLongHashMap();
for ( int i = 1; i <= element_count; i++ ) {
map.put( i, i * i );
}
for ( int i = 1; i <= element_count; i++ ) {
if ( i % 2 == 0 ) {
map.increment( i );
}
}
for ( int i = 1; i <= element_count; i++ ) {
if ( i % 2 == 0 ) {
assertEquals( i * i + 1, map.get( i ) );
} else {
assertEquals( i * i, map.get( i ) );
}
}
}
示例7: testSerialize
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testSerialize() throws Exception {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( map );
ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() );
ObjectInputStream ois = new ObjectInputStream( bias );
TIntLongMap deserialized = (TIntLongMap) ois.readObject();
assertEquals( map, deserialized );
}
示例8: testRehash
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
/** Be sure that size is large enough to force a resize or two. */
public void testRehash() {
int size = 1000;
int[] keys = new int[size];
long[] vals = new long[size];
for ( int i = 0; i < size; i++ ) {
keys[i] = i + 1;
vals[i] = keys[i] * 2;
}
TIntLongMap map = new TIntLongOffheapHashMap();
for ( int i = 0; i < keys.length; i++ ) {
map.put( keys[i], vals[i] );
}
assertEquals( keys.length, map.size() );
for ( int i = 0; i < keys.length; i++ ) {
int key = keys[i];
long val = vals[i];
assertEquals( "got incorrect value for index " + i + ", map: " + map,
val, map.get( key ) );
}
}
示例9: testClear
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testClear() {
int[] keys = {1138, 42, 86, 99, 101};
long[] vals = {1138, 42, 86, 99, 101};
TIntLongMap map = new TIntLongOffheapHashMap();
for ( int i = 0; i < keys.length; i++ ) {
map.put( keys[i], vals[i] * 2 );
}
assertEquals( keys.length, map.size() );
map.clear();
assertEquals( 0, map.size() );
assertTrue( map.isEmpty() );
TIntLongMap empty = new TIntLongOffheapHashMap();
assertEquals( empty, map );
// Map<String,String> jmap = new HashMap<String, String>();
// jmap.isEmpty()
}
示例10: testRemove
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testRemove() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap map = new TIntLongOffheapHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
assertEquals( keys.length, map.size() );
for ( int i = 0; i < keys.length; i++ ) {
assertEquals( vals[i], map.get( keys[i] ) );
}
assertEquals( vals[0], map.remove( keys[0] ) );
assertEquals( vals[3], map.remove( keys[3] ) );
assertEquals( map.getNoEntryValue(), map.remove( keys[0] ) );
assertEquals( vals[5], map.remove( keys[5] ) );
assertEquals( map.getNoEntryValue(), map.remove( 11010110 ) );
}
示例11: forEach
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
@Override
public void forEach(QuartIntLongConsumer action) {
for (int i = 0; i < values.length; i++)
for (int j = 0; j < values[i].length; j++)
for (int k = 0; k < values[i][j].length; k++) {
final int f1 = i;
final int f2 = j;
final TIntLongMap v = values[i][j][k];
if (v != null) {
final int f3 = k;
v.forEachEntry(
new TIntLongProcedure() {
@Override
public boolean execute(int a, long b) {
if (b > 0) action.accept(f1, f2, f3, a, b);
return true;
}
});
}
}
}
示例12: testValueCollectionHashCode
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testValueCollectionHashCode() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap map = new TIntLongOffheapHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
TLongCollection values = map.valueCollection();
assertEquals( map.size(), values.size() );
assertFalse( values.isEmpty() );
assertEquals( "hashcodes incorrectly not equal: " + map + ", " + values,
values.hashCode(), values.hashCode() );
assertFalse( "hashcodes incorrectly equal: " + map + ", " + values,
map.hashCode() == values.hashCode() );
}
示例13: testTransformValues
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testTransformValues() {
int element_count = 20;
TIntLongMap map = new TIntLongOffheapHashMap();
for ( int i = 1; i <= element_count; i++ ) {
map.put( i, i );
}
class TransformValues implements TLongFunction {
@Override
public long execute( long value ) {
return value * value;
}
}
TransformValues foreach = new TransformValues();
map.transformValues( foreach );
for ( int i = 1; i <= element_count; i++ ) {
assertEquals( i * i, map.get( i ) );
}
}
示例14: testAdjustValue
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testAdjustValue() {
TIntLongMap map = new TIntLongOffheapHashMap();
map.put( KEY_ONE, 1 );
boolean changed = map.adjustValue( KEY_ONE, 1 );
assertTrue( changed );
assertEquals( 2, map.get( KEY_ONE ) );
changed = map.adjustValue( KEY_ONE, 5 );
assertTrue( changed );
assertEquals( 7, map.get( KEY_ONE ) );
changed = map.adjustValue( KEY_ONE, -3 );
assertTrue( changed );
assertEquals( 4, map.get( KEY_ONE ) );
changed = map.adjustValue( KEY_TWO, 1 );
assertFalse( changed );
assertFalse( map.containsKey( KEY_TWO ) );
}
示例15: testAdjustOrPutValue
import gnu.trove.map.TIntLongMap; //导入依赖的package包/类
public void testAdjustOrPutValue() {
TIntLongMap map = new TIntLongOffheapHashMap();
map.put( KEY_ONE, 1 );
long new_value = map.adjustOrPutValue( KEY_ONE, 1, 100 );
assertEquals( 2, new_value );
assertEquals( 2, map.get( KEY_ONE ) );
new_value = map.adjustOrPutValue( KEY_ONE, 5, 100 );
assertEquals( 7, new_value );
assertEquals( 7, map.get( KEY_ONE ) );
new_value = map.adjustOrPutValue( KEY_ONE, -3, 100 );
assertEquals( 4, new_value );
assertEquals( 4, map.get( KEY_ONE ) );
new_value = map.adjustOrPutValue( KEY_TWO, 1, 100 );
assertEquals( 100, new_value );
assertTrue( map.containsKey( KEY_TWO ) );
assertEquals( 100, map.get( KEY_TWO ) );
new_value = map.adjustOrPutValue( KEY_TWO, 1, 100 );
assertEquals( 101, new_value );
assertEquals( 101, map.get( KEY_TWO ) );
}