当前位置: 首页>>代码示例>>Java>>正文


Java MutableHashTable类代码示例

本文整理汇总了Java中org.apache.flink.runtime.operators.hash.MutableHashTable的典型用法代码示例。如果您正苦于以下问题:Java MutableHashTable类的具体用法?Java MutableHashTable怎么用?Java MutableHashTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MutableHashTable类属于org.apache.flink.runtime.operators.hash包,在下文中一共展示了MutableHashTable类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addValues

import org.apache.flink.runtime.operators.hash.MutableHashTable; //导入依赖的package包/类
/**
 * Find for each value the right bucket on the deepest level and increase
 * its count
 */
@SuppressWarnings("unchecked")
private void addValues() {

	while (importIterator.hasNext()) {
		int nextValue = importIterator.next();

		HashMap<Integer, Object> mapForCurrentLevel = rootMap;

		for (int i = 0; i < maxLevel - 1; i++) {
			int hashValue = MutableHashTable.hash(nextValue, i);
			int bucket = rangeCalculators[i].getBucket(hashValue);
			Object nextObject = mapForCurrentLevel.get(bucket);
			if (nextObject == null) {
				HashMap<Integer, Object> mapForNextLevel = new HashMap<Integer, Object>();
				mapForCurrentLevel.put(bucket, mapForNextLevel);
				mapForCurrentLevel = mapForNextLevel;

			} else {
				mapForCurrentLevel = (HashMap<Integer, Object>) nextObject;
			}
		}

		int lastHashValue = MutableHashTable.hash(nextValue, maxLevel - 1);
		int deepestBucketNr = rangeCalculators[maxLevel - 1]
				.getBucket(lastHashValue);
		Object countOnDeepestLevel = mapForCurrentLevel
				.get(deepestBucketNr);
		if (countOnDeepestLevel == null) {
			mapForCurrentLevel.put(deepestBucketNr, 1);
		} else {
			mapForCurrentLevel.put(deepestBucketNr,
					((Integer) countOnDeepestLevel) + 1);
		}

	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:41,代码来源:HashFunctionCollisionBenchmark.java

示例2: testMutableHashMapPerformance

import org.apache.flink.runtime.operators.hash.MutableHashTable; //导入依赖的package包/类
@Test
public void testMutableHashMapPerformance() {
	try {
		final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
		
		MutableObjectIterator<IntPair> buildInput = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> probeInput = new UniformIntPairGenerator(0, 1, false);
		
		MutableObjectIterator<IntPair> probeTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		MutableObjectIterator<IntPair> updater = new UniformIntPairGenerator(NUM_PAIRS, 1, false);

		MutableObjectIterator<IntPair> updateTester = new UniformIntPairGenerator(NUM_PAIRS, 1, false);
		
		long start = 0L;
		long end = 0L;
		
		long first = System.currentTimeMillis();
		
		System.out.println("Creating and filling MutableHashMap...");
		start = System.currentTimeMillis();
		MutableHashTable<IntPair, IntPair> table = new MutableHashTable<IntPair, IntPair>(serializer, serializer, comparator, comparator, pairComparator, getMemory(NUM_MEM_PAGES, PAGE_SIZE), ioManager);				
		table.open(buildInput, probeInput);
		end = System.currentTimeMillis();
		System.out.println("HashMap ready. Time: " + (end-start) + " ms");
		
		System.out.println("Starting first probing run...");
		start = System.currentTimeMillis();
		IntPair compare = new IntPair();
		HashBucketIterator<IntPair, IntPair> iter;
		IntPair target = new IntPair(); 
		while(probeTester.next(compare) != null) {
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");

		System.out.println("Starting update...");
		start = System.currentTimeMillis();
		while(updater.next(compare) != null) {
			compare.setValue(compare.getValue()*-1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			iter.writeBack(compare);
			//assertFalse(iter.next(target));
		}
		end = System.currentTimeMillis();
		System.out.println("Update done. Time: " + (end-start) + " ms");
		
		System.out.println("Starting second probing run...");
		start = System.currentTimeMillis();
		while(updateTester.next(compare) != null) {
			compare.setValue(compare.getValue()*-1);
			iter = table.getMatchesFor(compare);
			iter.next(target);
			assertEquals(target.getKey(), compare.getKey());
			assertEquals(target.getValue(), compare.getValue());
			assertTrue(iter.next(target) == null);
		}
		end = System.currentTimeMillis();
		System.out.println("Probing done. Time: " + (end-start) + " ms");
		
		table.close();
		
		end = System.currentTimeMillis();
		System.out.println("Overall time: " + (end-first) + " ms");
		
		assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreedMemory().size());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail("Error: " + e.getMessage());
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:80,代码来源:HashTablePerformanceComparison.java


注:本文中的org.apache.flink.runtime.operators.hash.MutableHashTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。