Package com.tangosol.io.nio
Class BinaryMap
java.lang.Object
java.util.AbstractMap
com.tangosol.io.nio.BinaryMap
- All Implemented Interfaces:
- Map
Implements the Map interface to store Binary objects using Java's NIO
 buffers.
 
 The Buffer is used to hold blocks, which are either Entry or free blocks.
 Both share a common header:
   byte    length      type     description
   ------  ----------  -------  -------------------------------------------
        0           1  integer  type
        1           4  integer  offset of the next block in the Buffer
        5           4  integer  offset of the prev block in the Buffer
        9           4  integer  offset of the next entry in the list or -1=tail
       13           4  integer  offset of the prev entry in the list or -1=head
 The offset of the next block in the buffer provides the "length overall"
 (also known as LOA) of the block, such that a block located at offset
 "oCur" with a next block offset of "oNext" will have an LOA "l" of:
       l = oNext - oCur
 The additional structure for an Entry block is as follows:
   byte    length      type     description
   ------  ----------  -------  -------------------------------------------
       17           4  integer  hash code
       21           4  integer  key length (m)
       25           m  byte[]   key
     25+m           4  integer  value length (n)
     29+m           n  byte[]   value
   29+m+n  l-(29+m+n)  byte[]   fill
 The reason for supporting "fill" is to allow an entry to shrink and grow
 a little bit in place, for example since a free block has a minimum size
 and if the entry is followed immediately by another entry and shrinks, it
 would have to be moved if it doesn't shrink at least 17 bytes. Similarly,
 an entry could be padded to allow it to grow slightly.
 The additional structure for a free block is as follows:
   byte    length      type     description
   ------  ----------  -------  -------------------------------------------
       17        l-17  byte[]   fill
 The Buffer is a packed list of blocks, and each block is either an Entry or
 a free block. Contiguous free blocks are automatically merged so that there
 are never any contiguous free blocks at the end of an operation. Entries
 are expected to be contiguously allocated; compaction is the act of copying
 Entry blocks so that they are contiguous.
 The BinaryMap manages an array of hash buckets that hold the offsets of the
 first Entry in the linked list of entries stored in the Buffer. The offset
 will be NIL (-1) if there are no entries in that bucket since 0 is a valid
 offset into the Buffer.
 Incremental compaction occurs only on modifications (puts and removes).
 For a put, the compaction occurs before the put is processed, and for a
 remove, it occurs after the remove is processed, to make it slightly more
 likely that a put will have adequate free space and that the removed entry
 would not have been relocated by compaction.
 The BinaryMap categorizes empty blocks based on their size:
   code  free block size
   ----  -----------------------------------
      0  63 bytes or smaller
      1  64 to 127 bytes
      2  128 to 255 bytes
      3  256 to 511 bytes
      4  512 to 1023 bytes
      5  1024 to 2047 bytes
      6  2048 to 4095 bytes
      7  4096 to 8191 bytes
      8  8192 to 16383 bytes
      9  16384 to 32767 bytes
     10  32768 to 65535 bytes
     11  65536 to 131071 bytes
     12  131072 to 262143 bytes
     13  262144 to 524287 bytes
     14  524288 to 1048575 bytes
     15  1048576 to 2097151 bytes
     16  2097152 to 4194303 bytes
     17  4194304 to 8388607 bytes
     18  8388608 to 16777215 bytes
     19  16777216 to 33554431 bytes
     20  33554432 to 67108863 bytes
     21  67108864 to 134217727 bytes
     22  134217728 to 268435455 bytes
     23  268435456 to 536870911 bytes
     24  536870912 to 1073741823 bytes
     25  1073741824 to 2147483647 bytes
 For each category of free blocks, the BinaryMap maintains a linked list of
 free blocks that fit that category.
 To determine the size of a block in bytes, use the length() method. To
 calculate the code of a block, use the getSizeCode() method, or the static
 calculateSizeCode(int) method of BinaryMap.
 To open an existing block at a certain offset, use the method
 openBlock(int). To create and open a block at a certain offset, use the
 method initBlock(int). To allocate and open a free block of a certain size,
 use the method allocateBlock(int). An opened block should always be closed
 using the method Block.close(), which commits pending changes to the
 underlying buffer. The only time that a block should not be closed is when
 the block is being destroyed (e.g. when a free block is merged with another
 free block); in this case, use the method Block.discard().
 To merge free blocks that occur before and/or after a specific free block,
 use the method Block.merge(). To split a free block into two contiguous
 free blocks, use the method Block.split(int).
 To remove a block from its linked list, use Block.unlink(). Unless the
 block is being destroyed, it should be re-linked using the Block.link()
 method.
 - Since:
- Coherence 2.2
- Version:
- 1.00, 2002-09-06
- Author:
- cp
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionclassA Block is the unit of storage within a Buffer.static classA map entry (key-value pair).classA set of entries backed by this map.protected classA set of entries backed by this map.protected classA collection of values backed by this map.Nested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> 
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final int[]These are potential bucket counts.static final doubleDefault value for the percentage of the modulo that the entry count must reach before going to the next bucket level.static final doubleDefault value for the percentage of the next lower bucket level's modulo that the entry count must drop to before reverting to the next lower bucket level.protected static final byte[]Byte array used for wiping the buffer.protected static final byteByte used as a fill byte.protected BinaryMap.ValuesCollectionThe collection of values backed by this map.protected BinaryMap.EntrySetThe set of entries backed by this map.protected BinaryMap.KeySetThe set of keys backed by this map.protected static final intMaximum number of simultaneously open blocks to support.protected static final intNumber of size codes for free blocks.protected static final booleanTrue to enable debug mode.protected static final intOffset reserved for the "does-not-exist" block.protected static final intCopy buffer size.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstruct a BinaryMap.BinaryMap(ByteBufferManager bufmgr) Construct a BinaryMap using a buffer from the specified ByteBufferManager, and using the default modulo growth and shrinkage (load factor) settings.BinaryMap(ByteBufferManager bufmgr, double dflMaxLoadFactor, double dflMinLoadFactor, boolean fStrict) Construct a BinaryMap using a buffer from the specified ByteBufferManager, and using the specified modulo growth and shrinkage (load factor) settings.BinaryMap(ByteBuffer buffer) Construct a BinaryMap on a specific buffer with the default modulo growth and shrinkage (load factor) settings.BinaryMap(ByteBuffer buffer, double dflMaxLoadFactor, double dflMinLoadFactor, boolean fStrict) Construct a BinaryMap on a specific buffer with the specified modulo growth and shrinkage (load factor) settings.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidadjustOpenBlockOffset(int ofOld, int ofNew) When an open block changes position in the buffer, this method is invoked to adjust the cache of open blocks.protected BinaryMap.BlockallocateBlock(int cb) Allocate a free Block object of at least a certain size.protected static BinaryInternal debugging support: Turn a String into a Binary.protected static voidbuffercopy(ByteBuffer buffer, int ofCopyFrom, int ofCopyTo, int cbCopy, byte[] abBuf) Copy from one part of the buffer to another.protected intcalculateBucket(int nHash) Calculate the bucket for the specified hash code.protected intcalculatePreviousBucket(int nHash) Calculate the old bucket for the specified hash code.protected static intcalculateSizeCode(int cbBlock) Determine which "free bucket" a block of a particular size would go into.voidDebugging support: Validate the buffer's data structures, the hash buckets, free lists, etc.protected voidcheckBufferGrow(int cbAdditional) If there is a buffer manager, check if the current buffer should be grown.protected voidIf there is a buffer manager, check if the current buffer should be shrunk.protected voidDetermine if the modulo should be changed.voidclear()Removes all mappings from this map.protected voidClear out all references in the array of hash buckets.protected voidclearBucketOffsets(int nBucket) Clear out all references in the array of hash buckets starting with the specified bucket.protected voidCreate one big free block in the buffer.protected voidClear out all references in the array of free lists.protected voidFull linear compaction of the buffer.protected voidConfigure the incremental compact.protected voidComplete the incremental compact.protected voidPerform an incremental compaction of the next block.protected voidcompactUntil(int cbReqFree) Perform an an incremental compact at the specified block.booleancontainsKey(Object oKey) Returns true if this map contains a mapping for the specified key.voiddump()Debugging support: Dump the inner structures of the BinaryMap to stdout.entrySet()Returns a set view of the mappings contained in this map.protected BinaryMap.BlockfindEntryBlock(Binary binKey) Find the Entry block with the specified key.protected static StringformatIndex(int n) Format an index to a String.protected static StringformatOffset(int of) Format an offset to a String.protected static StringformatOffsetArray(int[] an) Format an array of offsets to be readable in a dump.Returns the value to which this map maps the specified key.protected intDetermine the number of hash buckets.protected intDetermine the hash bucket level.protected intgetBucketOffset(int nBucket) Get the first Entry block in the linked list of Entry blocks that fall into a certain hash bucket.protected ByteBufferObtain the ByteBuffer that the BinaryMap is backed by.protected DataInputStreamGet the DataInputStream that maps to the underlying ByteBuffer.Obtain the ByteBufferManager that provides the ByteBuffer objects.protected DataOutputStreamGet the DataOutputStream that maps to the underlying ByteBuffer.protected intDetermine the capacity of the map in bytes.intReturns the number of entry blocks.protected intgetFreeBlockOffset(int nCode) Get the first free block in the linked list of free blocks that have a certain size code.protected intDetermine the free capacity of the map in bytes.protected intDetermine the number of free lists (ie the number of size codes).protected intDetermine the level at which the modulo will increase.protected intGet the offset of the last block in the buffer.protected doubleDetermine the load factor for the map.protected doubleDetermine the "unload factor" for the map.protected intDetermine the current modulo.protected intDetermine the next block to compact.protected intDetermine the next bucket to rehash.protected intDetermine the previous modulo.protected intDetermine the level at which the modulo will decrease.protected intDetermine the number of types in the buffer that are in use by Entry blocks.protected BinaryMap.BlockgrabBlock(int ofBlock) Grab a block object for the specified offset.protected BinaryMap.BlockinitBlock(int of) Obtain a Block object for a new block that will be located at the specified offset in the ByteBuffer.protected voidCreate an initial array of hash buckets.protected voidCreate an array of references to lists of free blocks indexed by size code.protected BinaryMap.BlockFactory method: Create a Block object.protected BinaryMap.EntryinstantiateEntry(Binary binKey, Binary binValue) Factory pattern: Instantiate an Entry object.protected BinaryMap.EntrySetFactory pattern.protected BinaryMap.KeySetFactory pattern.protected BinaryMap.ValuesCollectionFactory pattern.protected booleanDetermine if the map is incrementally compacting.booleanisEmpty()Returns true if this map contains no key-value mappings.protected booleanDetermine if the map is incrementally rehashing.protected booleanisStrict()Determine if the buffer should be initialized and if blocks should be cleared when not in use.keySet()Returns a Set view of the keys contained in this map.static voidDebugging support: Command line test.protected BinaryMap.BlockopenBlock(int of) Obtain a Block object for the block located at the specified offset in the ByteBuffer.Associates the specified value with the specified key in this map.protected voidrecycleBlock(BinaryMap.Block block) Release (recycle) the specified Block object.protected voidrehash(int nBucket) Rehash the specified bucket such that, when done, it will only contain keys that hash to it with the current modulo.protected voidRehash all blocks such that no block will be linked into the wrong bucket.protected voidConfigure the incremental rehash.protected voidComplete the incremental rehash.protected voidRehash the next incremental rehash block.Removes the mapping for this key from this map if present.protected RuntimeExceptionreportOutOfMemory(int cbRequired) Report on an insufficient memory problem.protected voidsetBucketCount(int cBuckets) Configure the number of hash buckets.protected voidsetBucketLevel(int nLevel) Configure the hash bucket level.protected voidsetBucketOffset(int nBucket, int ofBlock) Set the head of the hash bucket linked list for a certain bucket.protected voidsetBuffer(ByteBuffer buffer) Specify the ByteBuffer that the BinaryMap will be backed by.protected voidsetBufferManager(ByteBufferManager bufmgr) Specify the ByteBufferManager for this map.protected voidsetFreeBlockOffset(int nCode, int ofBlock) Set the head of the free block linked list for a certain size code.protected voidsetGrowthCount(int cEntries) Set the level at which the modulo will increase.protected voidsetLastBlockOffset(int ofBlock) Set the offset of the last block in the buffer.protected voidsetMaxLoadFactor(double dflPercent) Set the load factor.protected voidsetMinLoadFactor(double dflPercent) Set the "unload factor".protected voidsetModulo(int nModulo) Set the new modulo.protected voidsetNextCompactBlock(int ofBlock) Set the next block to compact.protected voidsetNextRehashBucket(int nBucket) Set the next bucket to rehash.protected voidsetPreviousModulo(int nModulo) Set the old modulo.protected voidsetShrinkageCount(int cEntries) Set the level at which the modulo will decrease.protected voidsetStrict(boolean fStrict) Specify if the buffer should be initialized and if blocks should be cleared when not in use.intsize()Returns the number of key-value mappings in this map.protected static StringInternal debugging support: Turn a Binary into a String.protected Object[]Returns an array with a runtime type is that of the specified array and that contains data from all of the entries in this Map.protected RuntimeExceptionvalidateEntry(Object key, Object value, RuntimeException e) If the passed key and/or value is not a Binary object, then throw an exception to specify that the key is not Binary, otherwise throw the original exception.protected RuntimeExceptionvalidateKey(Object key, RuntimeException e) If the passed key is not Binary, then throw an exception to specify that the key is not Binary, otherwise throw the original exception.values()Returns a collection view of the values contained in this map.protected voidwipe(int of, int cb) Wipe a portion of the buffer.Methods inherited from class java.util.AbstractMapclone, containsValue, equals, hashCode, putAll, toStringMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
MODE_DEBUGprotected static final boolean MODE_DEBUGTrue to enable debug mode.- See Also:
 
- 
FILL_BYTEprotected static final byte FILL_BYTEByte used as a fill byte.- See Also:
 
- 
FILL_BUFFERprotected static final byte[] FILL_BUFFERByte array used for wiping the buffer.
- 
MAX_SIZE_CODESprotected static final int MAX_SIZE_CODESNumber of size codes for free blocks.- See Also:
 
- 
BUCKET_COUNTSprotected static final int[] BUCKET_COUNTSThese are potential bucket counts.
- 
SIZE_COPY_BUFFERprotected static final int SIZE_COPY_BUFFERCopy buffer size.- See Also:
 
- 
NILprotected static final int NILOffset reserved for the "does-not-exist" block.- See Also:
 
- 
MAX_OPEN_BLOCKSprotected static final int MAX_OPEN_BLOCKSMaximum number of simultaneously open blocks to support.- See Also:
 
- 
DEFAULT_MAXLOADFACTORpublic static final double DEFAULT_MAXLOADFACTORDefault value for the percentage of the modulo that the entry count must reach before going to the next bucket level.- See Also:
 
- 
DEFAULT_MINLOADFACTORpublic static final double DEFAULT_MINLOADFACTORDefault value for the percentage of the next lower bucket level's modulo that the entry count must drop to before reverting to the next lower bucket level.- See Also:
 
- 
m_setThe set of entries backed by this map.
- 
m_setKeysThe set of keys backed by this map.
- 
m_colValuesThe collection of values backed by this map.
 
- 
- 
Constructor Details- 
BinaryMapConstruct a BinaryMap on a specific buffer with the default modulo growth and shrinkage (load factor) settings.- Parameters:
- buffer- the ByteBuffer that the map will store its data in
 
- 
BinaryMappublic BinaryMap(ByteBuffer buffer, double dflMaxLoadFactor, double dflMinLoadFactor, boolean fStrict) Construct a BinaryMap on a specific buffer with the specified modulo growth and shrinkage (load factor) settings.- Parameters:
- buffer- the ByteBuffer that the map will store its data in
- dflMaxLoadFactor- the percentage of the ratio of keys to the modulo at which the modulo will increase; for example, 0.9 implies that the modulo will grow when the number of keys reaches 90% of the modulo value
- dflMinLoadFactor- the percentage of the ratio of keys to the next lower modulo at which the modulo will decrease; this value must be less than the maximum load factor value
- fStrict- true to enable the strict (clean buffer) option, which will degrade performance slightly
 
- 
BinaryMapConstruct a BinaryMap using a buffer from the specified ByteBufferManager, and using the default modulo growth and shrinkage (load factor) settings.- Parameters:
- bufmgr- the ByteBufferManager that is responsible for providing and managing the ByteBuffer
 
- 
BinaryMappublic BinaryMap(ByteBufferManager bufmgr, double dflMaxLoadFactor, double dflMinLoadFactor, boolean fStrict) Construct a BinaryMap using a buffer from the specified ByteBufferManager, and using the specified modulo growth and shrinkage (load factor) settings.- Parameters:
- bufmgr- the ByteBufferManager that is responsible for providing and managing the ByteBuffer
- dflMaxLoadFactor- the percentage of the ratio of keys to the modulo at which the modulo will increase; for example, 0.9 implies that the modulo will grow when the number of keys reaches 90% of the modulo value
- dflMinLoadFactor- the percentage of the ratio of keys to the next lower modulo at which the modulo will decrease; this value must be less than the maximum load factor value
- fStrict- true to enable the strict (clean buffer) option, which will degrade performance slightly
 
- 
BinaryMapprotected BinaryMap()Construct a BinaryMap. This constructor is provided solely for inheriting implementations to avoid the requirements imposed by the public constructors.
 
- 
- 
Method Details- 
sizepublic int size()Returns the number of key-value mappings in this map.- Specified by:
- sizein interface- Map
- Overrides:
- sizein class- AbstractMap
- Returns:
- the number of entries in this map
 
- 
isEmptypublic boolean isEmpty()Returns true if this map contains no key-value mappings.- Specified by:
- isEmptyin interface- Map
- Overrides:
- isEmptyin class- AbstractMap
- Returns:
- true if this map contains no key-value mappings
 
- 
containsKeyReturns true if this map contains a mapping for the specified key.- Specified by:
- containsKeyin interface- Map
- Overrides:
- containsKeyin class- AbstractMap
- Parameters:
- oKey- key whose presence in this map is to be tested
- Returns:
- true if this map contains a mapping for the specified key
 
- 
getReturns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key.- Specified by:
- getin interface- Map
- Overrides:
- getin class- AbstractMap
- Parameters:
- oKey- key whose associated value is to be returned
- Returns:
- the value to which this map maps the specified key, or null if the map contains no mapping for this key
 
- 
putAssociates the specified value with the specified key in this map.- Specified by:
- putin interface- Map
- Overrides:
- putin class- AbstractMap
- Parameters:
- oKey- key with which the specified value is to be associated
- oValue- value to be associated with the specified key
- Returns:
- previous value associated with specified key, or null if there was no mapping for key
 
- 
removeRemoves the mapping for this key from this map if present.- Specified by:
- removein interface- Map
- Overrides:
- removein class- AbstractMap
- Parameters:
- oKey- key whose mapping is to be removed from the map
- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
 
- 
clearpublic void clear()Removes all mappings from this map.- Specified by:
- clearin interface- Map
- Overrides:
- clearin class- AbstractMap
 
- 
entrySetReturns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.- Specified by:
- entrySetin interface- Map
- Specified by:
- entrySetin class- AbstractMap
- Returns:
- a set view of the mappings contained in this map.
 
- 
keySetReturns a Set view of the keys contained in this map. The Set is backed by the map, so changes to the map are reflected in the Set, and vice-versa. (If the map is modified while an iteration over the Set is in progress, the results of the iteration are undefined.) The Set supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.- Specified by:
- keySetin interface- Map
- Overrides:
- keySetin class- AbstractMap
- Returns:
- a Set view of the keys contained in this map
 
- 
valuesReturns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.- Specified by:
- valuesin interface- Map
- Overrides:
- valuesin class- AbstractMap
- Returns:
- a collection view of the values contained in this map
 
- 
getEntryBlockCountpublic int getEntryBlockCount()Returns the number of entry blocks.- Returns:
- the number of entry blocks
 
- 
findEntryBlockFind the Entry block with the specified key.- Parameters:
- binKey- the Binary key object
- Returns:
- a matching Entry block or null if that key is not in the map
 
- 
toArrayReturns an array with a runtime type is that of the specified array and that contains data from all of the entries in this Map. See the documentation for toArray for the key set, entry set and values collection of the map.- Parameters:
- ao- the array into which the data from the map entires are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
- conv- an object that converts a Block object into either a key, entry or value, depending on the collection which is delegating to this method
- Returns:
- an array containing the entry data (key, entry or value)
- Throws:
- ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type required to hold the keys, entries or values
 
- 
validateKeyIf the passed key is not Binary, then throw an exception to specify that the key is not Binary, otherwise throw the original exception.- Parameters:
- key- the object that should be of type Binary
- e- the original RuntimeException
- Throws:
- RuntimeException- this method always throws some form of RuntimeException
 
- 
validateEntryIf the passed key and/or value is not a Binary object, then throw an exception to specify that the key is not Binary, otherwise throw the original exception.- Parameters:
- key- the key object that should be of type Binary
- value- the value object that should be of type Binary
- e- the original RuntimeException
- Throws:
- RuntimeException- this method always throws some form of RuntimeException
 
- 
reportOutOfMemoryReport on an insufficient memory problem.- Parameters:
- cbRequired- the amount of space required
- Throws:
- RuntimeException- this method always throws some form of RuntimeException
 
- 
instantiateEntrySetFactory pattern.- Returns:
- a new instance of the EntrySet class (or a subclass thereof)
 
- 
instantiateKeySetFactory pattern.- Returns:
- a new instance of the KeySet class (or subclass thereof)
 
- 
instantiateValuesCollectionFactory pattern.- Returns:
- a new instance of the ValuesCollection class (or subclass thereof)
 
- 
instantiateEntryFactory pattern: Instantiate an Entry object.- Parameters:
- binKey- a Binary object for the key
- binValue- a Binary object for the value
- Returns:
- a new instance of the Entry class (or a subclass thereof)
 
- 
getBufferManagerObtain the ByteBufferManager that provides the ByteBuffer objects.- Returns:
- the ByteBufferManager object or null if there is none
 
- 
setBufferManagerSpecify the ByteBufferManager for this map.- Parameters:
- bufmgr- the ByteBufferManager object (or null)
 
- 
checkBufferGrowprotected void checkBufferGrow(int cbAdditional) If there is a buffer manager, check if the current buffer should be grown.- Parameters:
- cbAdditional- the number of bytes pending to be allocated in addition to the bytes currently used
 
- 
checkBufferShrinkprotected void checkBufferShrink()If there is a buffer manager, check if the current buffer should be shrunk.
- 
getBufferObtain the ByteBuffer that the BinaryMap is backed by.- Returns:
- the ByteBuffer object (never null)
 
- 
setBufferSpecify the ByteBuffer that the BinaryMap will be backed by.- Parameters:
- buffer- the new ByteBuffer object
 
- 
getCapacityprotected int getCapacity()Determine the capacity of the map in bytes.- Returns:
- the number of bytes that the buffer can hold
 
- 
getFreeCapacityprotected int getFreeCapacity()Determine the free capacity of the map in bytes.- Returns:
- the number of bytes in the buffer that are free
 
- 
getUsedCapacityprotected int getUsedCapacity()Determine the number of types in the buffer that are in use by Entry blocks.- Returns:
- the number of bytes in the buffer that are used
 
- 
getLastBlockOffsetprotected int getLastBlockOffset()Get the offset of the last block in the buffer.- Returns:
- the offset of the last block in the buffer
 
- 
setLastBlockOffsetprotected void setLastBlockOffset(int ofBlock) Set the offset of the last block in the buffer.- Parameters:
- ofBlock- the offset of the last block in the buffer
 
- 
isStrictprotected boolean isStrict()Determine if the buffer should be initialized and if blocks should be cleared when not in use.- Returns:
- true if freed parts of the buffer should be initialized
 
- 
setStrictprotected void setStrict(boolean fStrict) Specify if the buffer should be initialized and if blocks should be cleared when not in use.- Parameters:
- fStrict- pass true to always initialize unused portions of the buffer (which is slower but hides unused data)
 
- 
clearBufferprotected void clearBuffer()Create one big free block in the buffer.
- 
getBufferInputGet the DataInputStream that maps to the underlying ByteBuffer.- Returns:
- the DataInputStream that reads from the underlying ByteBuffer
 
- 
getBufferOutputGet the DataOutputStream that maps to the underlying ByteBuffer.- Returns:
- the DataOutputStream that writes to the underlying ByteBuffer
 
- 
wipeprotected void wipe(int of, int cb) Wipe a portion of the buffer.- Parameters:
- of- the offset into the buffer to wipe at
- cb- the number of bytes to wipe
 
- 
checkDebugging support: Validate the buffer's data structures, the hash buckets, free lists, etc.- Parameters:
- sDesc- a description of what is going on when this is called
 
- 
mainDebugging support: Command line test.- Parameters:
- asArg- command line arguments
 
- 
dumppublic void dump()Debugging support: Dump the inner structures of the BinaryMap to stdout.
- 
formatIndexFormat an index to a String.- Parameters:
- n- the index that (may be NIL)
- Returns:
- a decimal String (or "nil") containing the index in a readable form
 
- 
formatOffsetFormat an offset to a String.- Parameters:
- of- the offset that (may be NIL)
- Returns:
- a hex String (or "nil") containing the offset in a readable form
 
- 
formatOffsetArrayFormat an array of offsets to be readable in a dump.- Parameters:
- an- the array of offsets
- Returns:
- a String containing the offsets in a readable fashion
 
- 
binInternal debugging support: Turn a String into a Binary.- Parameters:
- s- a String (not null)
- Returns:
- a Binary containing the String's value (kind of like ASCII)
 
- 
strInternal debugging support: Turn a Binary into a String.- Parameters:
- bin- a Binary object or null
- Returns:
- a String with the Binary's contents unicode-extended or "<null>" if the passed Binary is null
 
- 
initializeFreeListsprotected void initializeFreeLists()Create an array of references to lists of free blocks indexed by size code.
- 
clearFreeListsprotected void clearFreeLists()Clear out all references in the array of free lists.
- 
getFreeListCountprotected int getFreeListCount()Determine the number of free lists (ie the number of size codes).- Returns:
- the number of free lists
 
- 
getFreeBlockOffsetprotected int getFreeBlockOffset(int nCode) Get the first free block in the linked list of free blocks that have a certain size code.- Parameters:
- nCode- the free block size code
- Returns:
- the offset of the first free block of that size code or NIL
 
- 
setFreeBlockOffsetprotected void setFreeBlockOffset(int nCode, int ofBlock) Set the head of the free block linked list for a certain size code.- Parameters:
- nCode- the free block size code
- ofBlock- the offset of the first free block of that size code or NIL
 
- 
initializeBucketsprotected void initializeBuckets()Create an initial array of hash buckets.
- 
getBucketLevelprotected int getBucketLevel()Determine the hash bucket level. Each level is associated with a specific pre-selected modulo.- Returns:
- the current hash bucket level
 
- 
setBucketLevelprotected void setBucketLevel(int nLevel) Configure the hash bucket level. Each level is associated with a specific pre-selected modulo. This mutator also sets the Modulo, GrowthCount and ShrinkageCount properties.- Parameters:
- nLevel- the new hash bucket level
 
- 
getBucketCountprotected int getBucketCount()Determine the number of hash buckets. This is not necessarily the modulo.- Returns:
- the number of hash buckets
 
- 
setBucketCountprotected void setBucketCount(int cBuckets) Configure the number of hash buckets. This does not change any offset values that are stored in the hash buckets; any additional buckets are initialized to NIL.- Parameters:
- cBuckets- the new number of hash buckets
 
- 
getBucketOffsetprotected int getBucketOffset(int nBucket) Get the first Entry block in the linked list of Entry blocks that fall into a certain hash bucket.- Parameters:
- nBucket- the bucket number
- Returns:
- the offset of the first Entry block in that bucket, or NIL
 
- 
setBucketOffsetprotected void setBucketOffset(int nBucket, int ofBlock) Set the head of the hash bucket linked list for a certain bucket.- Parameters:
- nBucket- the bucket number
- ofBlock- the offset of the first Entry block in that bucket, or NIL
 
- 
getMaxLoadFactorprotected double getMaxLoadFactor()Determine the load factor for the map. This is a value typically greater than zero and less than one, although technically it can be greater than one. This value, multiplied by the current modulo, provides the number of entries that will force growth of the map's modulo.- Returns:
- the load factor (aka the growth threshold)
 
- 
setMaxLoadFactorprotected void setMaxLoadFactor(double dflPercent) Set the load factor.- Parameters:
- dflPercent- the new load factor
 
- 
getMinLoadFactorprotected double getMinLoadFactor()Determine the "unload factor" for the map. This is a value typically greater than zero and less than one, although technically it can be greater than one. In any case, it must be smaller than the growth threshold (load factor). This value, multiplied by the next smaller modulo than the current modulo (i.e. the next lower bucket level), provides the number of entries that will force shrinkage of the map's modulo.- Returns:
- the "unload factor" (aka the shrinkage threshold)
 
- 
setMinLoadFactorprotected void setMinLoadFactor(double dflPercent) Set the "unload factor".- Parameters:
- dflPercent- the new "unload factor"
 
- 
getGrowthCountprotected int getGrowthCount()Determine the level at which the modulo will increase.- Returns:
- the number of entries at which the modulo will grow
 
- 
setGrowthCountprotected void setGrowthCount(int cEntries) Set the level at which the modulo will increase.- Parameters:
- cEntries- the number of entries at which the modulo will grow
 
- 
getShrinkageCountprotected int getShrinkageCount()Determine the level at which the modulo will decrease.- Returns:
- the number of entries at which the modulo will shrink
 
- 
setShrinkageCountprotected void setShrinkageCount(int cEntries) Set the level at which the modulo will decrease.- Parameters:
- cEntries- the number of entries at which the modulo will shrink
 
- 
getModuloprotected int getModulo()Determine the current modulo.- Returns:
- the current modulo
 
- 
setModuloprotected void setModulo(int nModulo) Set the new modulo.- Parameters:
- nModulo- the new modulo
 
- 
getPreviousModuloprotected int getPreviousModulo()Determine the previous modulo. If a hash bucket resize is still being processed, the previous modulo will be different from the current modulo.- Returns:
- the previous modulo
 
- 
setPreviousModuloprotected void setPreviousModulo(int nModulo) Set the old modulo.- Parameters:
- nModulo- the previous modulo
 
- 
calculateBucketprotected int calculateBucket(int nHash) Calculate the bucket for the specified hash code.- Parameters:
- nHash- the hash code for the key
- Returns:
- the bucket index
 
- 
calculatePreviousBucketprotected int calculatePreviousBucket(int nHash) Calculate the old bucket for the specified hash code.- Parameters:
- nHash- the hash code for the key
- Returns:
- the bucket index using the previous modulo
 
- 
clearBucketOffsetsprotected void clearBucketOffsets()Clear out all references in the array of hash buckets.
- 
clearBucketOffsetsprotected void clearBucketOffsets(int nBucket) Clear out all references in the array of hash buckets starting with the specified bucket. int nBucket the first bucket to clear
- 
checkModuloprotected void checkModulo()Determine if the modulo should be changed. This should only be checked when the map is growing to avoid problems with iterators when removing all entries (don't want the map to rehash then).
- 
isRehashingprotected boolean isRehashing()Determine if the map is incrementally rehashing.- Returns:
- true if the map is incrementally rehashing
 
- 
getNextRehashBucketprotected int getNextRehashBucket()Determine the next bucket to rehash.- Returns:
- the next bucket to rehash
 
- 
setNextRehashBucketprotected void setNextRehashBucket(int nBucket) Set the next bucket to rehash.- Parameters:
- nBucket- the next bucket to rehash
 
- 
rehashBeginprotected void rehashBegin()Configure the incremental rehash.
- 
rehashprotected void rehash(int nBucket) Rehash the specified bucket such that, when done, it will only contain keys that hash to it with the current modulo. Blocks can be in the "wrong" bucket because they are still hashed by the previous modulo; this is the result of incremental rehashing of buckets that allows a modulo change in a huge BinaryMap to occur instantly with the actual associated processing (rehashing) occuring gradually as the map is further used.- Parameters:
- nBucket- the bucket index to rehash
 
- 
rehashNextprotected void rehashNext()Rehash the next incremental rehash block.
- 
rehashAllprotected void rehashAll()Rehash all blocks such that no block will be linked into the wrong bucket. This is a no-op if a there is no re-hashing to do. Blocks can be in the "wrong" bucket because they are still hashed by the previous modulo; this is the result of incremental rehashing of buckets that allows a modulo change in a huge BinaryMap to occur instantly with the actual associated processing (rehashing) occuring gradually as the map is further used.
- 
rehashCompleteprotected void rehashComplete()Complete the incremental rehash.
- 
initBlockObtain a Block object for a new block that will be located at the specified offset in the ByteBuffer. The returned block is in an open state.- Returns:
- the Block object for the new block located at the specified offset
 
- 
openBlockObtain a Block object for the block located at the specified offset in the ByteBuffer. The returned block is in an open state.- Returns:
- the Block object for the block located at the specified offset
 
- 
allocateBlockAllocate a free Block object of at least a certain size. Note that the returned block is both open and unlinked.- Parameters:
- cb- the required block size
- Returns:
- a Block object of the required size
 
- 
isCompactingprotected boolean isCompacting()Determine if the map is incrementally compacting.- Returns:
- true if the map is incrementally compacting
 
- 
getNextCompactBlockprotected int getNextCompactBlock()Determine the next block to compact.- Returns:
- the next block to compact
 
- 
setNextCompactBlockprotected void setNextCompactBlock(int ofBlock) Set the next block to compact.- Parameters:
- ofBlock- the next block to compact
 
- 
compactBeginprotected void compactBegin()Configure the incremental compact.
- 
compactUntilprotected void compactUntil(int cbReqFree) Perform an an incremental compact at the specified block.- Parameters:
- cbReqFree- the number of bytes required to be free
 
- 
compactNextprotected void compactNext()Perform an incremental compaction of the next block.
- 
compactAllprotected void compactAll()Full linear compaction of the buffer.
- 
compactCompleteprotected void compactComplete()Complete the incremental compact.
- 
grabBlockGrab a block object for the specified offset. This method returns an open block if one is open for that offset, or uses a recycled block if one is not already open for that offset.- Parameters:
- ofBlock- the offset of the block to grab
- Returns:
- a block for the specified offset
 
- 
adjustOpenBlockOffsetprotected void adjustOpenBlockOffset(int ofOld, int ofNew) When an open block changes position in the buffer, this method is invoked to adjust the cache of open blocks.- Parameters:
- ofOld- the old offset of the block
- ofNew- the new offset of the block
 
- 
recycleBlockRelease (recycle) the specified Block object. This method should not be called directly; instead, call block.close().- Parameters:
- block- the Block object to release
 
- 
buffercopyprotected static void buffercopy(ByteBuffer buffer, int ofCopyFrom, int ofCopyTo, int cbCopy, byte[] abBuf) Copy from one part of the buffer to another. This method only supports copying from a latter part of the buffer to an earlier part of the buffer.- Parameters:
- buffer- the ByteBuffer containing the data to copy
- ofCopyFrom- the source offset into the ByteBuffer
- ofCopyTo- the destination offset into the ByteBuffer
- cbCopy- the number of bytes to copy
- abBuf- a temporary byte array available for use
 
- 
calculateSizeCodeprotected static int calculateSizeCode(int cbBlock) Determine which "free bucket" a block of a particular size would go into.- Parameters:
- cbBlock- the size of the block
- Returns:
- the size code for a block of the specified size
 
- 
instantiateBlockFactory method: Create a Block object.- Returns:
- a new instance of the Block class or subclass thereof
 
 
-