/* Copyright (c) 2008, Nathan Sweet
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
* - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
package com.alibaba.smart.framework.engine.common.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
/** An unordered map. This implementation is a cuckoo hash map using 3 hashes (if table size is less than 2^16) or 4 hashes
* (if table size is greater than or equal to 2^16), random walking, and a small stash for problematic keys Null keys are not
* allowed. Null values are allowed. No allocation is done except when growing the table size. <br>
* <br>
* This map performs very fast get, containsKey, and remove (typically O(1), worst case O(log(n))). Put may be a bit slower,
* depending on hash collisions. Load factors greater than 0.91 greatly increase the chances the map will have to rehash to the
* next higher POT size.
* @author Nathan Sweet */
public class ObjectMap<K, V> {
// primes for hash functions 2, 3, and 4
private static final int PRIME2 = 0xbe1f14b1;
private static final int PRIME3 = 0xb4b82e39;
private static final int PRIME4 = 0xced1c241;
static Random random = new Random();
public int size;
K[] keyTable;
V[] valueTable;
int capacity, stashSize;
private float loadFactor;
private int hashShift, mask, threshold;
private int stashCapacity;
private int pushIterations;
private boolean isBigTable;
/** Creates a new map with an initial capacity of 32 and a load factor of 0.8. This map will hold 25 items before growing the
* backing table. */
public ObjectMap () {
this(32, 0.8f);
}
/** Creates a new map with a load factor of 0.8. This map will hold initialCapacity * 0.8 items before growing the backing
* table. */
public ObjectMap (int initialCapacity) {
this(initialCapacity, 0.8f);
}
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity * loadFactor items
* before growing the backing table. */
public ObjectMap (int initialCapacity, float loadFactor) {
if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
capacity = nextPowerOfTwo(initialCapacity);
if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
this.loadFactor = loadFactor;
// big table is when capacity >= 2^16
isBigTable = (capacity >>> 16) != 0 ? true : false;
threshold = (int)(capacity * loadFactor);
mask = capacity - 1;
hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2);
pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8);
keyTable = (K[])new Object[capacity + stashCapacity];
valueTable = (V[])new Object[keyTable.length];
}
/** Creates a new map identical to the specified map. */
public ObjectMap (ObjectMap<? extends K, ? extends V> map) {
this(map.capacity, map.loadFactor);
stashSize = map.stashSize;
System.arraycopy(map.keyTable, 0, keyTable, 0, map.keyTable.length);
System.arraycopy(map.valueTable, 0, valueTable, 0, map.valueTable.length);
size = map.size;
}
/** Returns the old value associated with the specified key, or null. */
public V put (K key, V value) {
if (key == null) throw new IllegalArgumentException("key cannot be null.");
return put_internal(key, value);
}
private V put_internal (K key, V value) {
// avoid getfield opcode
K[] keyTable = this.keyTable;
int mask = this.mask;
boolean isBigTable = this.isBigTable;
// Check for existing keys.
int hashCode = key.hashCode();
int index1 = hashCode & mask;
K key1 = keyTable[index1];
if (key.equals(key1)) {
V oldValue = valueTable[index1];
valueTable[index1] = value;
return oldValue;
}
int index2 = hash2(hashCode);
K key2 = keyTable[index2];
if (key.equals(key2)) {
V oldValue = valueTable[index2];
valueTable[index2] = value;
return oldValue;
}
int index3 = hash3(hashCode);
K key3 = keyTable[index3];
if (key.equals(key3)) {
V oldValue = valueTable[index3];
valueTable[index3] = value;
return oldValue;
}
int index4 = -1;
K key4 = null;
if (isBigTable) {
index4 = hash4(hashCode);
key4 = keyTable[index4];
if (key.equals(key4)) {
V oldValue = valueTable[index4];
valueTable[index4] = value;
return oldValue;
}
}
// Update key in the stash.
for (int i = capacity, n = i + stashSize; i < n; i++) {
if (key.equals(keyTable[i])) {
V oldValue = valueTable[i];
valueTable[i] = value;
return oldValue;
}
}
// Check for empty buckets.
if (key1 == null) {
keyTable[index1] = key;
valueTable[index1] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (key2 == null) {
keyTable[index2] = key;
valueTable[index2] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (key3 == null) {
keyTable[index3] = key;
valueTable[index3] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
if (isBigTable && key4 == null) {
keyTable[index4] = key;
valueTable[index4] = value;
if (size++ >= threshold) resize(capacity << 1);
return null;
}
push(key, value, index1, key1, index2, key2, index3, key3, index4, key4);
return null;
}
public void putAll (ObjectMap<K, V> map) {
ensureCapacity(map.size);
for (Entry<K, V> entry : map.entries())
put(entry.key, entry.value);
}
/** Skips checks for existing keys. */
private void putResize (K key, V value) {
// Check for empty buckets.
int hashCode = key.hashCode();
int index1 = hashCode & mask;
K key1 = keyTable[index1];
if (key1 == null) {
keyTable[index1] = key;
valueTable[index1] = value;
if (size++ >= threshold) resize(capacity << 1);
return;
}
int index2 = hash2(hashCode);
K key2 = keyTable[index2];
if (key2 == null) {
keyTable[index2] = key;
valueTable[index2] = value;
if (size++ >= threshold) resize(capacity << 1);
return;
}
int index3 = hash3(hashCode);
K key3 = keyTable[index3];
if (key3 == null) {
keyTable[index3] = key;
valueTable[index3] = value;
if (size++ >= threshold) resize(capacity << 1);
return;
}
int index4 = -1;
K key4 = null;
if (isBigTable) {
index4 = hash4(hashCode);
key4 = keyTable[index4];
if (key4 ==
没有合适的资源?快使用搜索试试~ 我知道了~
SmartEngine:SmartEngine是轻型业务编排引擎
共613个文件
java:509个
xml:90个
properties:6个
需积分: 45 19 下载量 180 浏览量
2021-05-13
11:59:18
上传
评论 1
收藏 653KB ZIP 举报
温馨提示
智能引擎 SmartEngine是一个轻量级的业务编排引擎。 它在阿里巴巴集团中被广泛使用。 它可以用于在微服务架构中协调多种服务,以非常低的存储成本以非常高性能的方式启动/信号流程实例,也可以用于传统的流程批准场景中。 设计哲学 吻(保持简单,愚蠢) 标准化:采用BPMN2.0,指定通用语言。 可扩展的:例如解析器,行为,存储,用户集成等 高性能:在某些简单的过程场景中,提供了一种提高性能并降低存储成本的简单方法。 更少的依赖:从一开始,我们就尽力避免JAR地狱。 主要特征 CQRS风格的API,用于启动,信号,查询流程实例,任务,活动。 支持基本的BPMN符号:StartEvent,EndEvent,SequenceFlow,ExclusiveGateway,ServiceTask,ReceiveTask。 在某些简单的过程场景中,提供一种简单的方法来提高性能并降低存储成
资源详情
资源评论
资源推荐
收起资源包目录
SmartEngine:SmartEngine是轻型业务编排引擎 (613个子文件)
.gitignore 192B
ObjectMap.java 23KB
DefaultExecutionCommandService.java 18KB
MongoTaskInstanceStorage.java 18KB
UserTaskBehavior.java 15KB
ProcessServiceTest.java 14KB
DefaultParallelServiceOrchestration.java 14KB
CustomCallActivityTest.java 14KB
RelationshipDatabaseTaskInstanceStorage.java 13KB
DefaultRepositoryCommandService.java 13KB
ServiceOrchestrationParallelGatewayTest.java 13KB
DeploymentServiceTest.java 12KB
CallActivityParallelGateWayTest.java 12KB
DefaultTaskCommandService.java 12KB
ParalleyGatewayAndCallActivityTest.java 12KB
UserTaskBehaviorHelper.java 12KB
RelationshipDatabaseProcessInstanceStorage.java 11KB
CompatibleActivitiAndCustomExtensionProcessTest.java 11KB
VariableInstanceAndMultiInstanceTest.java 11KB
MongoProcessInstanceStorage.java 11KB
MongoTaskAssigneeInstanceStorage.java 11KB
CommonServiceHelper.java 11KB
DataBaseCallActivityTest.java 10KB
DefaultProcessCommandService.java 10KB
RelationshipDatabaseExecutionInstanceStorage.java 9KB
DefaultDeploymentCommandService.java 9KB
SmartEngineBenchmark.java 9KB
SimpleAnnotationScanner.java 9KB
InstanceSerializerV1.java 9KB
ParallelGateWayListenerIssueTest.java 9KB
RelationshipDatabaseDeploymentInstanceStorage.java 9KB
RelationshipDatabaseVariableInstanceStorage.java 9KB
RelationshipDatabaseTaskAssigneeInstanceStorage.java 9KB
ParallelGatewayBehavior.java 8KB
MongoExecutionInstanceStorage.java 8KB
MultiInstanceCompatibleAllModelPassedTest.java 8KB
JumpFreeNode2Test.java 8KB
ParallelGateWayListenerIssueConfiguration.java 8KB
TaskServiceTest.java 7KB
MongoActivityInstanceStorage.java 7KB
BasicParallelGatewayTest.java 7KB
MultiInstanceTest.java 7KB
DataBaseAuditProcessExample.java 7KB
ProcessSimulation.java 7KB
InstanceSerializer.java 7KB
DefaultSmartEngine.java 6KB
RelationshipDatabaseActivityInstanceStorage.java 6KB
LockStrategyTest.java 6KB
DefaultContextFactory.java 6KB
DefaultXmlParserFacade.java 6KB
AbstractActivityBehavior.java 6KB
DatabaseBaseTestCase.java 6KB
ExtenstionTest.java 6KB
EmbeddedParallelGatewayTest.java 5KB
DelegationAndListenerExecutorExtensionTest.java 5KB
ProcessEngineConfiguration.java 5KB
CustomExecutionInstanceStorage.java 5KB
DefaultProcessEngineConfiguration.java 5KB
MultiInstanceCompatibleAllModelFailFastTest.java 5KB
DefaultProcessDefinitionContainer.java 5KB
RetryTest.java 5KB
ParaGatewayUserTaskProcessTest.java 5KB
MultiInstanceCompatibleAnyModelAbortTest.java 4KB
ClassUtil.java 4KB
MultiInstanceCompatibleAnyModelFailedFastTest.java 4KB
VariableServiceTest.java 4KB
ExtensionNameSpaceParseTest.java 4KB
MongoUserTaskTest.java 4KB
JumpFreeNode1Test.java 4KB
InheritableTaskWithCache.java 4KB
MixedAuditProcessTest.java 4KB
CommonTestCode.java 4KB
DefaultProcessInstanceFactory.java 4KB
DefaultTaskQueryService.java 4KB
CallActivityBehavior.java 4KB
XmlParseUtil.java 4KB
AbstractElementParser.java 4KB
CustomTaskInstanceStorage.java 4KB
SmartEngineFactoryBean.java 4KB
ProcessDefinitionParser.java 4KB
MultiInstanceCompatibleAnyModelPassedTest.java 4KB
MockProcessInstanceTest.java 4KB
TransactionHelper.java 4KB
DefaultRetryService.java 4KB
TransactionTest.java 4KB
DefaultDelegationExecutor.java 3KB
RelationshipDatabaseRetryRecordStorage.java 3KB
MarkDoneUtil.java 3KB
ProcessInstanceDAOTest.java 3KB
CustomActivityInstanceStorage.java 3KB
TaskInstanceDAOTest.java 3KB
InstanceSerializerFacade.java 3KB
TaskAssigneeInstanceDAOTest.java 3KB
CompatiableOldVersionProcessDefinitionTest.java 3KB
FirstBasicProcessTest.java 3KB
DeploymentInstanceDAOTest.java 3KB
MemoryRetryRecordStorage.java 3KB
CustomTaskAssigneeInstanceStorage.java 3KB
ServiceOrchestrationTest.java 3KB
CustomRetryRecordStorage.java 3KB
共 613 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
信徒阿布
- 粉丝: 39
- 资源: 4576
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 人工智能实验四 感知器算法的设计实现
- java小项目多线程多线程 复制文件 冒泡排序 群聊
- 四数之和(java代码).docx
- 701837906919458TapScanner v3.0.10 (Pro).apk
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 289ssm-mysql-jsp 计算机课程实验管理系统.zip(可运行源码+数据库文件+文档)
- 毕业设计,基于PyQt5实现的可视化界面的Python车牌自动识别系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0