edu.isi.stella
Class KeyValueMap

java.lang.Object
  extended by edu.isi.stella.Stella_Object
      extended by edu.isi.stella.StandardObject
          extended by edu.isi.stella.AbstractCollection
              extended by edu.isi.stella.AbstractDictionary
                  extended by edu.isi.stella.Dictionary
                      extended by edu.isi.stella.KeyValueMap
Direct Known Subclasses:
HashSet

public class KeyValueMap
extends Dictionary

Full-featured dictionary class that supports eqlP or equalP equality tests, O(1) access operations even for large numbers of entries by using a hash table, light-weight KV-CONS representation for small tables and iteration even if the dictionary is represented by a hash table.


Field Summary
 int crossoverPoint
           
 boolean equalTestP
          If true use equalP as the equality test (and equalHashCode as the hash function), otherwise, use eqlP (and hashCode) (the default).
 int initialSize
          If supplied, the initial table will be sized to hold at least that many elements.
 Stella_Object theMap
           
 
Constructor Summary
KeyValueMap()
           
 
Method Summary
static Stella_Object accessKeyValueMapSlotValue(KeyValueMap self, Symbol slotname, Stella_Object value, boolean setvalueP)
           
 AbstractIterator allocateIterator()
          Allocate an iterator for self.
 void clear()
          Reset self to have zero entries.
 Cons consify()
          Collect all entries of self into a cons list of _LkeyGLvalueG_ pairs and return the result.
 KeyValueMap copy()
          Return a copy of the map self.
 boolean emptyP()
          Return TRUE if self has zero entries.
 int equalHashCode()
          Return an equalP hash code for self.
 void insertAt(Stella_Object key, Stella_Object value)
          Set the value of the entry identified by key in self to value or add a new entry if no entry with key exists yet.
 int length()
          Return the number of entries in self.
 Stella_Object lookup(Stella_Object key)
          Lookup the entry identified by key in self and return its value, or NULL if no such entry exists.
static KeyValueMap newKeyValueMap()
           
 boolean nonEmptyP()
          Return TRUE if self has at least 1 entry.
 boolean objectEqualP(Stella_Object y)
          Return TRUE if x and y represent the same set of key/value pairs.
 Surrogate primaryType()
          Returns the primary type of self.
 void removeAt(Stella_Object key)
          Remove the entry identified by key from self.
 
Methods inherited from class edu.isi.stella.StandardObject
arrayTypeSpecifierP, baseTypeToTypeSpec, cantOverwriteActiveCollectionSlot, compatibleParameterTypesP, computeAnchoredTypeSpec, computeRelativeTypeSpec, conformingTypeSpecP, copyWrappedLiteral, cppReferenceTypeP, cppReferencizeType, cppTranslateAndPointerizeTypeSpec, cppTranslateAndReferencizeTypeSpec, cppTranslateTypeSpec, dropSlotValue, extractParameterType, extractRequiredArgumentValues, getSlot, hashCode_, idlTranslateTypeSpec, inverseSlotDemon, javaLiteralP, javaNativeLiteralWrapperNames, javaSpecialSetterName, javaTranslateArrayOfTypeSpec, javaTranslateTypeSpec, javaTranslateTypeSpecForFunction, javaTranslateTypeSpecHelper, javaYieldClassObjectArrayExpression, javaYieldClassObjectExpression, javaYieldFullyQualifiedTypeName, javaYieldTranslatedClassAndMethodNames, listifyTypeSpec, lookupClTypeFromStellaType, objectEqlP, putSlotValue, readSlotValue, runConstructorDemons, runDestructorDemons, runSlotDemons, runSlotGuardDemonsP, standardObjectP, subTypeSpecOfP, twoArgumentLeastCommonSupertype, typeSpecToBaseType, typeSpecToClass, typeToWalkedNullValueTree, validateTypeSpecifier, voidP, walkTypeSpecIsNativeTypeP, writeSlotValue, yieldTypeSpecTree
 
Methods inherited from class edu.isi.stella.Stella_Object
_, accessInContext, amPm, anchoredTypeSpecifierP, andOrNotTreeP, applyCoercionMethod, atomicExpressionP, bindToSurrogateP, booleanP, bootstrapIsaP, bquotify, cast, characterP, clTranslateAtomicTree, clTranslateATree, clTranslateBooleanTest, clTranslatePlainBooleanTest, clTranslateVerbatimBodySymbols, clYieldTypedExpressionTree, coerceATree, coerceEvaluatedTree, coerceMvTree, coerceToBoolean, coerceToModule, coerceToModuleName, coerceToSymbol, coerceToXmlElement, coercibleP, collectFeatureList, collectKeyValueList, commonLispSymbolP, computeExpressionType, cons, consifyListsAndIterators, consP, consTreeMatchP, convertToLiteral, copyConsTree, cppArgumentIsStreamP, cppBinaryOperatorP, cppBlockP, cppMaybeOutputStatementWithParentheses, cppOperatorP, cppOutputAtomicExpression, cppOutputLiteral, cppOutputOneActualParameter, cppOutputStatement, cppOutputTypedEntity, cppPrognifyStatement, cppPrognP, cppStatementToList, cppStreamIsStandardOutputP, cpptrans, cppTranslateAtomicTree, cppTranslateATree, cppTranslatedArrayTypeP, csValueP, dateDivider, dateTimeDivider, day, dealWithAmPm, dealWithEra, dealWithNoonMidn, decrementReferenceCount, defaultOptionHandler, defineSystem, defmodule, deletedP, describe, describeObject, describeTersely, destructureMethodNameTree, deUglifyParseTree, either, eqlP, eqlToBooleanP, eqlToCharacterP, eqlToFloatP, eqlToIntegerP, eqlToStringP, equalConsTreesP, equalP, era, estimatedEvaluationCost, evaluate, evaluateArgumentTree, evaluateAtomicTree, evaluateCommand, expandBquoteTree, filterModuleP, floatP, free, get, getObject, hashlist, hashMemoizedArguments, helpBquotify, helpClTranslateATree, helpCoerceATree, helpLptrans, helpPrintOutline, helpTransformBooleanProceduralExpression, helpWalkATree, homeModule, hour, idlOutputAtomicExpression, idlOutputLiteral, idlOutputStatement, idlTranslateAtomicTree, idlTranslateATree, illegalTreeP, implodePathname, incrementallyTranslate, incrementReferenceCount, inlineUnwrapBoolean, inlineWrapBoolean, inModule, integerP, isaP, javaBinaryOperatorP, javaBlockP, javaEndOfLineTokenP, javaHelpOutputPrintStream, javaMaybeOutputStatementWithParentheses, javaOperatorP, javaOutputLiteral, javaOutputStatement, javaPrognP, javaStreamIsStandardOutputP, javaSymbolCaseP, javaTranslateAtomicTree, javaTranslateATree, javaTranslateWithNativeWrapper, jptrans, keywordP, kvCons, legalTokenizerFromStateP, legalTokenizerStateP, legalTokenizerToStateP, literalEqlP, logLevelLE, lptrans, makeFileNameFromRelativePath, makeMemoizedValueEntry, makeMemoizedValueEntryn, matchConsTree, methodSlotP, minute, month, nameToString, nilP, noonMidn, numberWrapperToFloat, objectHashCode, one, oneI, onlyIf, parametricTypeSpecifierP, parseArrayDimensionsSpec, parseTokenizerCharacterSpec, parseTokenizerStateModifiers, permanentCopy, permanentify, permanentifyForm, po, prettyPrintLiteral, primaryClass, printObject, printOutline, printStellaCode, printStellaDefinition, printUndefinedSuperClasses, proceduralExpressionP, ptrans, publicSlots, registerRecycledItem, runOptionHandlerP, safeEqualHashCode, safeHashCode, safePrimaryType, safeYieldTypeSpecifier, searchConsTreeP, searchConsTreeWithFilterP, searchForObject, secondp, sideEffectFreeExpressionP, simplifyBquoteTree, specialp, stella_Increment, stellaClassP, stellaCollectionP, stellaNeedToCompileP, stellaNeedToTranslateP, stellaObjectP, stellify, storageSlotP, stringifyInModule, stringP, substituteConsTree, substituteOnce, surrogateP, surrogatify, sweep, symbolCaseP, symbolP, sysTree, targetLanguageType, taxonomyIsaP, timeDivider, timeMultiply, tokenizerIncludeSpecP, tokenizerToStateAlias, tokenizerToStateName, toString, traceIf, traceKeywordP, transientifyForm, transientObjectP, transientSymbolP, translateWalkedTree, treeSize, treeToTrees, trueOptionP, tryToEvaluate, typeP, typify, unmake, unregisterRecycledItem, updateInContext, valuesTreeP, variableExpressionP, verbatimStringP, verbatimTreeP, vetOptions, vrletExpressionP, walkAtomicTree, walkATree, walkCollectionTree, walkDontCallMeTree, walkedExpressionType, walkExpressionTree, walkMvExpressionTree, walkMvTree, walkStatement, walkTopLevelExpression, walkWithoutTypeTree, warnAboutUnknownSourceType, weekday, withinContext, withinModule, withinWorld, withStellaTokenizer, withSystemDefinition, withTokenizer, wrapperP, wrapWhereTest, xmlAttributeP, xmlCdataFormP, xmlCdataP, xmlDeclarationFormP, xmlDeclarationP, xmlDoctypeFormP, xmlElementFormP, xmlElementP, xmlnsAttributeP, xmlProcessingInstructionFormP, xmlProcessingInstructionP, xmlTagCase, year, yieldCondTest, yieldCondTestOrTests, yieldHardcodedCaseSymbolIdOrIds, yieldInCursorClausesForArgumentList, yieldInCursorClausesForGeneralCollection, yieldInCursorClausesForVector, yieldTypeSpecifier, zone, zoneMinute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

theMap

public Stella_Object theMap

equalTestP

public boolean equalTestP
If true use equalP as the equality test (and equalHashCode as the hash function), otherwise, use eqlP (and hashCode) (the default).


initialSize

public int initialSize
If supplied, the initial table will be sized to hold at least that many elements.


crossoverPoint

public int crossoverPoint
Constructor Detail

KeyValueMap

public KeyValueMap()
Method Detail

newKeyValueMap

public static KeyValueMap newKeyValueMap()

equalHashCode

public int equalHashCode()
Return an equalP hash code for self. Note that this is O(N) in the number of entries of self.

Overrides:
equalHashCode in class Stella_Object
Returns:
int

objectEqualP

public boolean objectEqualP(Stella_Object y)
Return TRUE if x and y represent the same set of key/value pairs.

Overrides:
objectEqualP in class Stella_Object
Parameters:
y -
Returns:
boolean

consify

public Cons consify()
Collect all entries of self into a cons list of _LkeyGLvalueG_ pairs and return the result.

Overrides:
consify in class Stella_Object
Returns:
Cons

allocateIterator

public AbstractIterator allocateIterator()
Allocate an iterator for self. The only modifying operations allowed during iteration are removal of the current element or changing its value. All other removal or insertion operations might lead to corruption or undefined results.

Overrides:
allocateIterator in class Dictionary
Returns:
AbstractIterator

clear

public void clear()
Reset self to have zero entries.


copy

public KeyValueMap copy()
Return a copy of the map self. All entries are freshly allocated, however, the keys and values of entries are not copied themselves (similar to what we do for lists, etc.).

Returns:
KeyValueMap

nonEmptyP

public boolean nonEmptyP()
Return TRUE if self has at least 1 entry.

Returns:
boolean

emptyP

public boolean emptyP()
Return TRUE if self has zero entries.

Returns:
boolean

length

public int length()
Return the number of entries in self.

Overrides:
length in class AbstractCollection
Returns:
int

removeAt

public void removeAt(Stella_Object key)
Remove the entry identified by key from self. Uses an eqlP test by default or equalP if equalTestP of self is TRUE.

Parameters:
key -

insertAt

public void insertAt(Stella_Object key,
                     Stella_Object value)
Set the value of the entry identified by key in self to value or add a new entry if no entry with key exists yet. Uses an eqlP test by default or equalP if equalTestP of self is TRUE.

Overrides:
insertAt in class Dictionary
Parameters:
key -
value -

lookup

public Stella_Object lookup(Stella_Object key)
Lookup the entry identified by key in self and return its value, or NULL if no such entry exists. Uses an eqlP test by default or equalP if equalTestP of self is TRUE.

Overrides:
lookup in class Dictionary
Parameters:
key -
Returns:
Stella_Object

accessKeyValueMapSlotValue

public static Stella_Object accessKeyValueMapSlotValue(KeyValueMap self,
                                                       Symbol slotname,
                                                       Stella_Object value,
                                                       boolean setvalueP)

primaryType

public Surrogate primaryType()
Description copied from class: Stella_Object
Returns the primary type of self. Gets defined automatically for every non-abstract subclass of OBJECT.

Overrides:
primaryType in class Stella_Object
Returns:
Surrogate