本文整理汇总了Java中gnu.trove.map.TIntLongMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java TIntLongMap.put方法的具体用法?Java TIntLongMap.put怎么用?Java TIntLongMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.map.TIntLongMap
的用法示例。
在下文中一共展示了TIntLongMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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 raw_map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
raw_map.put( keys[i], vals[i] * 2 );
}
Map<Integer,Long> map = TDecorators.wrap( raw_map );
assertEquals( keys.length, map.size() );
map.clear();
assertEquals( 0, map.size() );
assertTrue( map.isEmpty() );
TIntLongMap raw_empty = new TIntLongHashMap();
Map<Integer,Long> empty = TDecorators.wrap( raw_empty );
assertEquals( empty, map );
}
示例2: 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 );
}
示例3: 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 ) );
}
示例4: testEquals
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testEquals() {
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( map, map );
TIntIntMap int_map = new TIntIntOffheapHashMap();
for ( int i = 0; i < keys.length; i++ ) {
int_map.put( keys[i], (int) vals[i] );
}
assertFalse( map.equals( int_map ) );
}
示例5: 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 raw_map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
raw_map.put( keys[i], vals[i] );
}
Map<Integer,Long> map = TDecorators.wrap( raw_map );
assertEquals( keys.length, map.size() );
for ( int i = 0; i < keys.length; i++ ) {
Integer key = keys[i];
Long val = vals[i];
assertEquals( "got incorrect value for index " + i + ", map: " + map,
val, map.get( key ) );
}
}
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:24,代码来源:TPrimitivePrimitiveMapDecoratorTest.java
示例6: 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 ) );
}
}
示例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 raw_map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
raw_map.put( keys[i], vals[i] );
}
Map<Integer,Long> map = TDecorators.wrap( raw_map );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( map );
ByteArrayInputStream bias = new ByteArrayInputStream( baos.toByteArray() );
ObjectInputStream ois = new ObjectInputStream( bias );
//noinspection unchecked
Map<Integer,Long> deserialized = (Map<Integer,Long>) ois.readObject();
assertEquals( map, deserialized );
}
开发者ID:leventov,项目名称:trove-over-koloboke-compile,代码行数:24,代码来源:TPrimitivePrimitiveMapDecoratorTest.java
示例8: 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 TIntLongHashMap();
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 ) );
}
示例9: testConstructors
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testConstructors() {
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] );
}
assertEquals( keys.length, map.size() );
TIntLongMap capacity = new TIntLongOffheapHashMap( 20 );
for ( int i = 0; i < keys.length; i++ ) {
capacity.put( keys[i], vals[i] );
}
assertEquals( keys.length, capacity.size() );
TIntLongMap cap_and_factor = new TIntLongOffheapHashMap( 20, 0.75f );
for ( int i = 0; i < keys.length; i++ ) {
cap_and_factor.put( keys[i], vals[i] );
}
assertEquals( keys.length, cap_and_factor.size() );
// Equals in all combinations is paranoid.. but..
assertEquals( map, map );
assertEquals( map, capacity );
assertEquals( map, cap_and_factor );
assertEquals( capacity, map );
assertEquals( capacity, capacity );
assertEquals( capacity, cap_and_factor );
assertEquals( cap_and_factor, map );
assertEquals( cap_and_factor, capacity );
assertEquals( cap_and_factor, cap_and_factor );
}
示例10: testEquals
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testEquals() {
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] );
}
assertEquals( map, map );
TIntIntMap int_map = new TIntIntHashMap();
for ( int i = 0; i < keys.length; i++ ) {
int_map.put( keys[i], (int) vals[i] );
}
assertFalse( map.equals( int_map ) );
// Change a value..
TIntLongMap unequal = new TIntLongHashMap( map );
map.put( keys[3], vals[3] + 1 );
assertFalse( map.equals( unequal ) );
// Change length
unequal = new TIntLongHashMap( map );
map.put( 13, 26 );
assertFalse( map.equals( unequal ) );
}
示例11: testPutIfAbsent
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testPutIfAbsent() {
TIntLongMap map = new TIntLongHashMap();
map.put( 1, 10 );
map.put( 2, 20 );
map.put( 3, 30 );
assertEquals( 10, map.putIfAbsent( 1, 111 ) );
assertEquals( 10, map.get( 1 ) );
assertEquals( map.getNoEntryValue(), map.putIfAbsent( 9, 90 ) );
assertEquals( 90, map.get( 9 ) );
}
示例12: testValueCollectionContainsAll
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testValueCollectionContainsAll() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap raw_map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
raw_map.put( keys[i], vals[i] );
}
Map<Integer,Long> map = TDecorators.wrap( raw_map );
Collection<Long> values = map.values();
assertEquals( map.size(), values.size() );
assertFalse( values.isEmpty() );
// test with a java.util.Map
Set<Number> java_set = new HashSet<Number>();
for ( long val : vals ) {
java_set.add( Long.valueOf( val ) );
}
assertTrue( values.containsAll( java_set ) );
java_set.add( Integer.valueOf( 12 ) );
assertFalse( values.containsAll( java_set ) );
java_set.remove( Integer.valueOf( 12 ) );
assertTrue( values.containsAll( java_set ) );
java_set.add( Long.valueOf( 12 ) );
assertFalse( values.containsAll( java_set ) );
}
示例13: testKeySetRemoveAllArray
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testKeySetRemoveAllArray() {
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] );
}
TIntSet set = map.keySet();
assertEquals( map.size(), set.size() );
assertFalse( set.isEmpty() );
// test raw array
map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
set = map.keySet();
keys[3] = keys[3] + 1;
assertTrue( set.removeAll( keys ) );
keys[3] = keys[3] - 1;
assertEquals( "removed: " + keys[3] + ", set: " + set,
1, set.size() );
assertEquals( "removed: " + keys[3] + ", set: " + set
+ "\nmap: " + map, set.size(), map.size() );
}
示例14: testKeySetEquals
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testKeySetEquals() {
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] );
}
TIntSet set = map.keySet();
assertEquals( map.size(), set.size() );
assertFalse( set.isEmpty() );
TIntSet other = new TIntHashSet();
other.addAll( keys );
assertTrue( "sets incorrectly not equal: " + set + ", " + other,
set.equals( other ) );
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntHashSet();
unequal.addAll( mismatched );
assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
set.equals( unequal ) );
// Change length, different code branch
unequal.add( 1 );
assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
set.equals( unequal ) );
assertFalse( "set incorrectly equals a random object",
set.equals( new Object() ) );
}
示例15: testValueCollectionRemoveAllArray
import gnu.trove.map.TIntLongMap; //导入方法依赖的package包/类
public void testValueCollectionRemoveAllArray() {
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] );
}
TLongCollection values = map.valueCollection();
assertEquals( map.size(), values.size() );
assertFalse( values.isEmpty() );
// test raw array
map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
values = map.valueCollection();
vals[3] = vals[3] + 1;
assertTrue( values.removeAll( vals ) );
vals[3] = vals[3] - 1;
assertEquals( "removed: " + keys[3] + ", values: " + values,
1, values.size() );
assertEquals( "removed: " + keys[3] + ", values: " + values
+ "\nmap: " + map, values.size(), map.size() );
}