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


Java HTreeMap类代码示例

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


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

示例1: addMapDataToList

import org.mapdb.HTreeMap; //导入依赖的package包/类
/**
 * add data from a given map in the db to the list.
 *
 * @param mapName
 *            the map name to use.
 * @param keyBa
 *            the key ba to use.
 * @param list
 *            the list to add to.
 * @param factory
 *            the factory to use.
 * @param <T>
 *            the type of object the factory makes.
 */
private <T> void addMapDataToList(final String mapName, final byte[] keyBa, final List<T> list,
		final AbstractByteBufferFactory<T> factory) {
	if (LOG.isTraceEnabled()) {
		LOG.trace("addMapDataToList {} keyBa:{}", mapName, ModelUtil.toHexString(keyBa));
	}
	final HTreeMap<byte[], byte[]> map = DB.hashMap(mapName, Serializer.BYTE_ARRAY, Serializer.BYTE_ARRAY)
			.counterEnable().createOrOpen();
	final byte[] listBa = map.get(keyBa);
	if (LOG.isTraceEnabled()) {
		LOG.trace("addMapDataToList {} listBa:{}", mapName, ModelUtil.toHexString(listBa));
	}

	final List<byte[]> baList = ModelUtil.toByteArrayList(listBa);
	for (final byte[] ba : baList) {
		final ByteBuffer bb = ByteBuffer.wrap(ba);
		final T t = factory.toObject(bb);
		list.add(t);
	}
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:34,代码来源:BlockDbMapDbImpl.java

示例2: getAccountAssetValueMap

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public Map<UInt160, Map<UInt256, Fixed8>> getAccountAssetValueMap() {
	final Map<UInt160, Map<UInt256, Fixed8>> accountAssetValueMap = new TreeMap<>();

	final TransactionOutputFactory objectFactory = new TransactionOutputFactory();

	final HTreeMap<Long, byte[]> map = getByteArrayByBlockIndexMap(TRANSACTION_OUTPUTS_BY_HASH);
	for (final long key : map.getKeys()) {
		final byte[] listBa = map.get(key);
		final List<byte[]> baList = ModelUtil.toByteArrayList(listBa);
		for (final byte[] ba : baList) {
			final TransactionOutput output = objectFactory.toObject(ByteBuffer.wrap(ba));

			if (!accountAssetValueMap.containsKey(output.scriptHash)) {
				accountAssetValueMap.put(output.scriptHash, new TreeMap<>());
			}
			final Map<UInt256, Fixed8> assetValueMap = accountAssetValueMap.get(output.scriptHash);
			assetValueMap.put(output.assetId, output.value);
		}
	}

	return accountAssetValueMap;
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:24,代码来源:BlockDbMapDbImpl.java

示例3: getBlock

import org.mapdb.HTreeMap; //导入依赖的package包/类
/**
 * return the block at the given height, with transactions attached.
 *
 * @param blockHeight
 *            the block height to use.
 * @param withTransactions
 *            if true, add transactions. If false, only return the block header.
 * @return the block at the given height.
 */
private Block getBlock(final long blockHeight, final boolean withTransactions) {
	synchronized (this) {
		if (closed) {
			return null;
		}
	}

	final HTreeMap<Long, byte[]> map = getBlockHeaderByIndexMap();
	if (!map.containsKey(blockHeight)) {
		return null;
	}

	final Block block = new Block(ByteBuffer.wrap(map.get(blockHeight)));
	if (withTransactions) {
		getTransactionsForBlock(block);
	}
	return block;
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:28,代码来源:BlockDbMapDbImpl.java

示例4: getTransactionsForBlock

import org.mapdb.HTreeMap; //导入依赖的package包/类
/**
 * return the block, with transactions added.
 *
 * @param block
 *            the block, to add transactions to.
 */
private void getTransactionsForBlock(final Block block) {
	final long blockIndex = block.getIndexAsLong();

	final HTreeMap<Long, byte[]> txKeyListMap = getByteArrayByBlockIndexMap(TRANSACTION_KEYS_BY_BLOCK_INDEX);
	final List<byte[]> txKeyBaList = getByteArrayList(txKeyListMap, blockIndex);

	final HTreeMap<byte[], byte[]> txMap = getTransactionsByKeyMap();
	for (final byte[] txKey : txKeyBaList) {
		if (LOG.isTraceEnabled()) {
			LOG.trace("getTransactionsForBlock {} txKey:{}", blockIndex, ModelUtil.toHexString(txKey));
		}
		final byte[] data = txMap.get(txKey);
		final Transaction transaction = new Transaction(ByteBuffer.wrap(data));
		getTransactionOutputs(txKey, transaction);
		getTransactionInputs(txKey, transaction);
		getTransactionScripts(txKey, transaction);
		block.getTransactionList().add(transaction);
	}
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:26,代码来源:BlockDbMapDbImpl.java

示例5: close

import org.mapdb.HTreeMap; //导入依赖的package包/类
/**
 * This function closes all the file handles that where created or opened
 * during the lifetime of the class instance. If it is not called, a
 * <code>org.mapdb.DBException$DataCorruption</code> will be thrown on the
 *  next execution of the application when using the same project path.
 */
public void close(){
	
	AptaLogger.log(Level.CONFIG, this.getClass(), "Closing pool file handles.");
	
	// Iterate over each TreeMap instance and close it
	ListIterator<HTreeMap<byte[], Integer>> li = poolData.listIterator(poolData.size());
	while(li.hasPrevious()) { li.previous().close(); }

	// Close the bounds data
	ListIterator<BTreeMap<Integer, int[]>> bi = boundsData.listIterator(boundsData.size());
	while(bi.hasPrevious()) { bi.previous().close(); }

	// Close the inverse view
	ListIterator<BTreeMap<Integer, byte[]>> lii = poolDataInverse.listIterator(poolDataInverse.size());
	while(lii.hasPrevious()) { lii.previous().close(); }
}
 
开发者ID:drivenbyentropy,项目名称:aptasuite,代码行数:23,代码来源:MapDBAptamerPool.java

示例6: create

import org.mapdb.HTreeMap; //导入依赖的package包/类
@NotNull
@Override
public <T extends Serializable> T create(@NotNull String namespace, @NotNull String key, @NotNull T value) throws StorageBackendException, StorageOperationException {
    checkArguments(namespace, key, value);

    HTreeMap<String, Object> namespaceMap = internalOpenNamespace(namespace);
    LOGGER.trace("Create namespace={}, key={}, value={}", namespace, key, value);

    if (namespaceMap.containsKey(key)) {
        LOGGER.debug("Creation failed: key {} exists already in namespace {}", key, namespace);
        throw new StorageOperationException("Creation failed: key already exists", namespace, key);
    } else {
        LOGGER.debug("Created key {} in namespace {}", key, namespace);
        namespaceMap.put(key, value);
    }

    return value;
}
 
开发者ID:jhendess,项目名称:metadict,代码行数:19,代码来源:MapdbStorageEngine.java

示例7: read

import org.mapdb.HTreeMap; //导入依赖的package包/类
@NotNull
@Override
public <T extends Serializable> Optional<T> read(@NotNull String namespace, @NotNull String key, Class<T> clazz) throws StorageBackendException, StorageOperationException {
    checkArguments(namespace, key);

    HTreeMap<String, Object> namespaceMap = internalOpenNamespace(namespace);

    LOGGER.trace("Reading namespace={}, key={}", namespace, key);

    try {
        T readValue = clazz.cast(namespaceMap.get(key));
        return Optional.ofNullable(readValue);
    } catch (ClassCastException e) {
        throw new StorageOperationException("Reading value failed due to an invalid class cast", namespace, key, e);
    }
}
 
开发者ID:jhendess,项目名称:metadict,代码行数:17,代码来源:MapdbStorageEngine.java

示例8: update

import org.mapdb.HTreeMap; //导入依赖的package包/类
@NotNull
@Override
public <T extends Serializable> T update(@NotNull String namespace, @NotNull String key, @NotNull T newValue) throws StorageBackendException, StorageOperationException {
    checkArguments(namespace, key, newValue);

    HTreeMap<String, Object> namespaceMap = internalOpenNamespace(namespace);

    LOGGER.trace("Put namespace={}, key={}, value={}", namespace, key, newValue);

    if (!namespaceMap.containsKey(key)) {
        throw new StorageOperationException("Update failed: key doesn't exist", namespace, key);
    }

    namespaceMap.put(key, newValue);

    return newValue;
}
 
开发者ID:jhendess,项目名称:metadict,代码行数:18,代码来源:MapdbStorageEngine.java

示例9: hdel

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public void hdel(HeboCallback callback, final String key, final String hkey) {

    exec.execute(new SafeRunner("hdel", callback) {

        @Override
        public void invoke() {
            if (dbmakerForHashmap.exists(key)) {
                HTreeMap<String, String> map = (HTreeMap<String, String>) dbmakerForHashmap.get(key);
                callback.integerValue(map.remove(hkey) == null ? 0 : 1);
                if (map.isEmpty()) {
                    dbmakerForHashmap.delete(key);
                }
            } else {
                callback.integerValue(0);
            }
        }
    });

}
 
开发者ID:guokr,项目名称:hebo,代码行数:21,代码来源:HeboEngineImpl.java

示例10: hset

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public void hset(HeboCallback callback, final String key, final String hkey, final String hvalue) {

    exec.execute(new SafeRunner("hset", callback) {

        @Override
        public void invoke() {
            HTreeMap<String, String> map = null;
            if (dbmakerForHashmap.exists(key)) {
                map = (HTreeMap<String, String>) dbmakerForHashmap.get(key);
            } else {
                map = dbmakerForHashmap.createHashMap(key).make();
            }
            callback.integerValue(map.put(hkey, hvalue) == null ? 1 : 0);
        }
    });

}
 
开发者ID:guokr,项目名称:hebo,代码行数:19,代码来源:HeboEngineImpl.java

示例11: hgetall

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public void hgetall(HeboCallback callback, final String key) {

    exec.execute(new SafeRunner("hgetall", callback) {

        @Override
        public void invoke() {
            if (dbmakerForHashmap.exists(key)) {
                HTreeMap<String, String> map = (HTreeMap<String, String>) dbmakerForHashmap.get(key);
                Set<String> keyset = map.keySet();
                String result[] = new String[map.size() * 2];
                int idx = 0;
                for (String k : keyset) {
                    result[idx++] = k;
                    result[idx++] = map.get(k);
                }
                callback.stringList(result);
            } else {
                callback.stringList(new String[0]);
            }
        }
    });

}
 
开发者ID:guokr,项目名称:hebo,代码行数:25,代码来源:HeboEngineImpl.java

示例12: hget

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public void hget(HeboCallback callback, final String key, final String hkey) {

    exec.execute(new SafeRunner("hget", callback) {

        @Override
        public void invoke() {
            if (dbmakerForHashmap.exists(key)) {
                HTreeMap<String, String> map = (HTreeMap<String, String>) dbmakerForHashmap.get(key);
                callback.stringValue(map.get(hkey));
            } else {
                callback.stringValue(null);
            }
        }
    });

}
 
开发者ID:guokr,项目名称:hebo,代码行数:18,代码来源:HeboEngineImpl.java

示例13: rpush

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public void rpush(HeboCallback callback, final String key, final String value) {

    exec.execute(new SafeRunner("rpush", callback) {

        @Override
        public void invoke() {
            HTreeMap<Integer, String> map = null;
            if (dbmaker.exists(key)) {
                map = (HTreeMap<Integer, String>) dbmaker.get(key);
            } else {
                map = dbmaker.createHashMap(key).make();
            }
            map.put(map.size(), value);

            callback.integerValue(map.size());
        }
    });

}
 
开发者ID:guokr,项目名称:hebo,代码行数:21,代码来源:HeboEngineImpl.java

示例14: llen

import org.mapdb.HTreeMap; //导入依赖的package包/类
@Override
public void llen(HeboCallback callback, final String key) {

    exec.execute(new SafeRunner("llen", callback) {

        @Override
        public void invoke() {
            if (dbmaker.exists(key)) {
                HTreeMap<Integer, String> map = (HTreeMap<Integer, String>) dbmaker.get(key);
                callback.integerValue(map.size());
            } else {
                callback.integerValue(0);
            }
        }
    });

}
 
开发者ID:guokr,项目名称:hebo,代码行数:18,代码来源:HeboEngineImpl.java

示例15: clearCache

import org.mapdb.HTreeMap; //导入依赖的package包/类
/**
 * NB: Disables caching on finalize in cleared cells. This is done to prevent
 * immortal cells. Caching must be re-enabled per-cell if desired.
 *
 * @see CacheService#clearCache(String)
 */
@Override
public void clearCache(final String cacheId) {
	if (caches.contains(cacheId)) {
		final HTreeMap<?, ?> cache = db().getHashMap(cacheId);

		// Disable re-caching in all cells of this cache and remove them.
		for (final Object k : cache.keySet()) {
			knownKeys.remove(k);
			retrievedKeys.remove(k);
			final SCIFIOCell<?> cell = (SCIFIOCell<?>) cache.remove(k);
			if (cell != null) cell.cacheOnFinalize(false);
		}
		db().commit();
	}
}
 
开发者ID:scifio,项目名称:scifio,代码行数:22,代码来源:MapDBCache.java


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