private int combineToSameRoot(int rootCounter, int consRoot, int prodRoot) { //combine these two roots. int newRootId = ++rootCounter; if (!IntHashTable.setItem(rootsTable, consRoot, newRootId)) { throw new UnsupportedOperationException(); } if (!IntHashTable.setItem(rootsTable, prodRoot, newRootId)) { throw new UnsupportedOperationException(); } return rootCounter; }
private static int combineToSameRoot(int rootCounter, int consRoot, int prodRoot, IntHashTable rootsTable) { //combine these two roots. int newRootId = ++rootCounter; if (!IntHashTable.setItem(rootsTable, consRoot, newRootId)) { throw new UnsupportedOperationException(); } if (!IntHashTable.setItem(rootsTable, prodRoot, newRootId)) { throw new UnsupportedOperationException(); } return rootCounter; }
public int storeAlias(int sessionId, int newStructId) { if (!IntHashTable.setItem(aliasStructIdTable, sessionId, newStructId)) { aliasStructIdTable = IntHashTable.doubleSize(aliasStructIdTable); if (!IntHashTable.setItem(aliasStructIdTable, sessionId, newStructId)) { logger.warn("internal error, unable to store new struct id for reuse.", new Exception()); } } return newStructId; }
public int storeAlias(int sessionId, int newStructId) { if (!IntHashTable.setItem(aliasStructIdTable, sessionId, newStructId)) { aliasStructIdTable = IntHashTable.doubleSize(aliasStructIdTable); if (!IntHashTable.setItem(aliasStructIdTable, sessionId, newStructId)) { logger.warn("internal error, unable to store new struct id for reuse.", new Exception()); } } return newStructId; }
public void populateListenerIdentityHash(Behavior listener) { //store this value for lookup later //logger.info("adding hash listener {} to pipe ",System.identityHashCode(listener)); if (!IntHashTable.setItem(subscriptionPipeLookup, System.identityHashCode(listener), subscriptionPipeIdx++)) { throw new RuntimeException("Could not find unique identityHashCode for "+listener.getClass().getCanonicalName()); } assert(!IntHashTable.isEmpty(subscriptionPipeLookup)); }
public void populateListenerIdentityHash(int hash) { //store this value for lookup later //logger.info("adding hash listener {} to pipe ",System.identityHashCode(listener)); if (!IntHashTable.setItem(subscriptionPipeLookup, hash, subscriptionPipeIdx++)) { throw new RuntimeException("Could not find unique identityHashCode for "+hash); } assert(!IntHashTable.isEmpty(subscriptionPipeLookup)); }
public static IntHashTable doubleSize(IntHashTable ht) { IntHashTable newHT = new IntHashTable(ht.bits+1); int j = ht.mask+1; while (--j >= 0) { long block = ht.data[j]; if (0!=block) { int key = (int)block; int value = (int)(block>>32); setItem(newHT, key, value); } } return newHT; }
public static IntHashTable doubleSize(IntHashTable ht) { IntHashTable newHT = new IntHashTable(ht.bits+1); int j = ht.mask+1; while (--j >= 0) { long block = ht.data[j]; if (0!=block) { int key = (int)block; int value = (int)(block>>32); setItem(newHT, key, value); } } assert(newHT.space>0); return newHT; }
public static IntHashTable doubleSize(IntHashTable ht) { IntHashTable newHT = new IntHashTable(ht.bits+1); int j = ht.mask+1; while (--j >= 0) { long block = ht.data[j]; if (0!=block) { int key = (int)block; int value = (int)(block>>32); setItem(newHT, key, value); } } assert(newHT.space>0); return newHT; }
public void registerStructAssociation(int structId, Object associatedObject) { int key = associatedObject.hashCode(); assert(!IntHashTable.hasItem(structTable, key)) : "These objects are too similar or was attached twice, Hash must be unique. Choose different objects"; if (IntHashTable.hasItem(structTable, key)) { logger.warn("Unable to add object {} as an association, Another object with an identical Hash is already held. Try a different object.", associatedObject); return; } if (!IntHashTable.setItem(structTable, key, structId)) { structTable = IntHashTable.doubleSize(structTable); if (!IntHashTable.setItem(structTable, key, structId)) { throw new RuntimeException("internal error"); }; } }
public void registerRouteAssociation(int routeId, Object associatedObject) { int key = associatedObject.hashCode(); assert(!IntHashTable.hasItem(routeIdTable, key)) : "These objects are too similar or was attached twice, Hash must be unique. Choose different objects"; if (IntHashTable.hasItem(routeIdTable, key)) { logger.warn("Unable to add object {} as an association, Another object with an identical Hash is already held. Try a different object.", associatedObject); return; } if (!IntHashTable.setItem(routeIdTable, key, routeId)) { routeIdTable = IntHashTable.doubleSize(routeIdTable); if (!IntHashTable.setItem(routeIdTable, key, routeId)) { throw new RuntimeException("internal error"); }; } }
public void registerStructAssociation(int structId, Object associatedObject) { int key = associatedObject.hashCode(); assert(!IntHashTable.hasItem(structTable, key)) : "These objects are too similar or was attached twice, Hash must be unique. Choose different objects"; if (IntHashTable.hasItem(structTable, key)) { logger.warn("Unable to add object {} as an association, Another object with an identical Hash is already held. Try a different object.", associatedObject); return; } if (!IntHashTable.setItem(structTable, key, structId)) { structTable = IntHashTable.doubleSize(structTable); if (!IntHashTable.setItem(structTable, key, structId)) { throw new RuntimeException("internal error"); }; } structLocals[structId&STRUCT_MASK] = associatedObject; }
public void registerStructAssociation(int structId, Object associatedObject) { int key = associatedObject.hashCode(); assert(!IntHashTable.hasItem(structTable, key)) : "These objects are too similar or was attached twice, Hash must be unique. Choose different objects"; if (IntHashTable.hasItem(structTable, key)) { logger.warn("Unable to add object {} as an association, Another object with an identical Hash is already held. Try a different object.", associatedObject); return; } if (!IntHashTable.setItem(structTable, key, structId)) { structTable = IntHashTable.doubleSize(structTable); if (!IntHashTable.setItem(structTable, key, structId)) { throw new RuntimeException("internal error"); }; } structLocals[structId&STRUCT_MASK] = associatedObject; }
public final ListenerFilter includeSerialStoreReleaseAck(int ... id) { serialStoreRelAckPipeMap = new IntHashTable(IntHashTable.computeBits(id.length*3)); int i = id.length; while (--i>=0) { Pipe<PersistedBlobLoadReleaseSchema> pipe = builder.serialStoreReleaseAck[i]; if (pipe==null) { throw new UnsupportedOperationException("The id "+id+" release ack has already been assined to another behavior.\n Only 1 behavior may consume this message"); } else { IntHashTable.setItem(serialStoreRelAckPipeMap, NON_ZERO_BASE+pipe.id, NON_ZERO_BASE+i); builder.serialStoreReleaseAck[i] = null; } } return this; }
public final ListenerFilter includeSerialStoreReplay(int ... id) { serialStoreReplayPipeMap = new IntHashTable(IntHashTable.computeBits(id.length*3)); int i = id.length; while (--i>=0) { Pipe<PersistedBlobLoadConsumerSchema> pipe = builder.serialStoreReplay[i]; if (pipe==null) { throw new UnsupportedOperationException("The id "+id+" replay has already been assined to another behavior.\n Only 1 behavior may consume this message"); } else { IntHashTable.setItem(serialStoreReplayPipeMap, NON_ZERO_BASE+pipe.id, NON_ZERO_BASE+i); builder.serialStoreReplay[i] = null; } } return this; }
public final ListenerFilter includeSerialStoreWriteAck(int ... id) { serialStoreProdAckPipeMap = new IntHashTable(IntHashTable.computeBits(id.length*3)); int i = id.length; while (--i>=0) { Pipe<PersistedBlobLoadProducerSchema> pipe = builder.serialStoreWriteAck[i]; if (pipe==null) { throw new UnsupportedOperationException("The id "+id+" write ack has already been assined to another behavior.\n Only 1 behavior may consume this message"); } else { IntHashTable.setItem(serialStoreProdAckPipeMap, NON_ZERO_BASE+pipe.id, NON_ZERO_BASE+i); builder.serialStoreWriteAck[i] = null; } } return this; }
/** * * @param child Object arg used for System.identityHashCode * @param topParent Object arg used for System.identityHashCode * @param usageChecker IntHashTable arg compared against parentHash * @return if IntHashTable.hasItem and parentHash!=IntHashTable return false else true */ public static boolean notPreviouslyHeld(Object child, Object topParent, IntHashTable usageChecker) { int hash = System.identityHashCode(child); int parentHash = System.identityHashCode(topParent); if (IntHashTable.hasItem(usageChecker, hash)) { if (parentHash!=IntHashTable.getItem(usageChecker, hash)) { return false; } } //keep so this is detected later if use IntHashTable.setItem(usageChecker, hash, parentHash); return true; } ///////////
private boolean addAssocHashToTable(Object localObject, int structIdx, int fieldIdx) { if (null==this.fieldAttachedIndex[structIdx]) { this.fieldAttachedIndex[structIdx] = new IntHashTable( IntHashTable.computeBits(this.fieldLocals[structIdx].length*2) ); } int hashCode = localObject.hashCode(); assert(0!=hashCode) : "can not insert null"; assert(!IntHashTable.hasItem(this.fieldAttachedIndex[structIdx], hashCode)) : "These objects are too similar or was attached twice, Hash must be unique. Choose different objects"; if (IntHashTable.hasItem(this.fieldAttachedIndex[structIdx], hashCode)) { logger.warn("Unable to add object {} as an association, Another object with an identical Hash is already held. Try a different object.", localObject); return false; } else { if (!IntHashTable.setItem(this.fieldAttachedIndex[structIdx], hashCode, fieldIdx)) { //we are out of space this.fieldAttachedIndex[structIdx] = IntHashTable.doubleSize(this.fieldAttachedIndex[structIdx]); if (!IntHashTable.setItem(this.fieldAttachedIndex[structIdx], hashCode, fieldIdx)) { throw new RuntimeException("internal error"); } } else { //logger.info("{} set object {} to index {}",structIdx, localObject, fieldIdx); } assert(fieldIdx == IntHashTable.getItem(this.fieldAttachedIndex[structIdx], hashCode)); return true; } }
private static < T extends Enum<T> & HTTPContentType> IntHashTable buildFileExtHashTable(Class<T> supportedHTTPContentTypes) { int hashBits = 13; //8K IntHashTable localExtTable = new IntHashTable(hashBits); T[] conentTypes = supportedHTTPContentTypes.getEnumConstants(); int c = conentTypes.length; while (--c >= 0) { if (!conentTypes[c].isAlias()) {//never use an alias for the file Ext lookup. int hash = HTTPSpecification.extHash(conentTypes[c].fileExtension()); if ( IntHashTable.hasItem(localExtTable, hash) ) { final int ord = IntHashTable.getItem(localExtTable, hash); throw new UnsupportedOperationException("Hash error, check for new values and algo. "+conentTypes[c].fileExtension()+" colides with existing "+conentTypes[ord].fileExtension()); } else { IntHashTable.setItem(localExtTable, hash, conentTypes[c].ordinal()); } } } return localExtTable; }