Class ImmutableExternalPrefixMap

    • Field Detail

      • STD_BLOCK_SIZE

        public static final int STD_BLOCK_SIZE
        The standard block size (in bytes).
        See Also:
        Constant Field Values
      • intervalApproximator

        protected final ImmutableBinaryTrie<CharSequence> intervalApproximator
        The in-memory data structure used to approximate intervals..
      • blockSize

        protected final long blockSize
        The block size of this (in bits).
      • decoder

        protected final Decoder decoder
        A decoder used to read data from the dump stream.
      • symbol2char

        protected final char[] symbol2char
        A map (given by an array) from symbols in the coder to characters.
      • char2symbol

        protected final Char2IntOpenHashMap char2symbol
        A map from characters to symbols of the coder.
      • size

        protected final long size
        The number of terms in this map.
      • blockStart

        protected final long[][] blockStart
        The index of the first word in each block, plus an additional entry containing Function.size().
      • blockOffset

        protected final long[][] blockOffset
        A big array array parallel to blockStart giving the offset in blocks in the dump file of the corresponding word in blockStart. If there are no overflows, this will just be an initial segment of the natural numbers, but overflows cause jumps.
      • selfContained

        protected final boolean selfContained
        Whether this map is self-contained.
      • iteratorIsUsable

        protected transient boolean iteratorIsUsable
        If true, the creation of the last DumpStreamIterator was not followed by a call to any get method.
      • dumpStream

        protected transient InputBitStream dumpStream
        A reference to the dump stream.
    • Constructor Detail

      • ImmutableExternalPrefixMap

        public ImmutableExternalPrefixMap​(Iterable<? extends CharSequence> terms,
                                          int blockSizeInBytes,
                                          CharSequence dumpStreamFilename)
                                   throws IOException
        Creates an external prefix map with specified block size and dump stream.

        This constructor does not assume that CharSequence instances returned by terms.iterator() will be distinct. Thus, it can be safely used with FileLinesCollection.

        Parameters:
        terms - an iterable whose iterator will enumerate in lexicographical order the terms for the map.
        blockSizeInBytes - the block size (in bytes).
        dumpStreamFilename - the name of the dump stream, or null for a self-contained map.
        Throws:
        IOException
      • ImmutableExternalPrefixMap

        public ImmutableExternalPrefixMap​(Iterable<? extends CharSequence> terms,
                                          CharSequence dumpStreamFilename)
                                   throws IOException
        Creates an external prefix map with block size STD_BLOCK_SIZE and specified dump stream.

        This constructor does not assume that CharSequence instances returned by terms.iterator() will be distinct. Thus, it can be safely used with FileLinesCollection.

        Parameters:
        terms - a collection whose iterator will enumerate in lexicographical order the terms for the map.
        dumpStreamFilename - the name of the dump stream, or null for a self-contained map.
        Throws:
        IOException
      • ImmutableExternalPrefixMap

        public ImmutableExternalPrefixMap​(Iterable<? extends CharSequence> terms,
                                          int blockSizeInBytes)
                                   throws IOException
        Creates an external prefix map with specified block size.

        This constructor does not assume that CharSequence instances returned by terms.iterator() will be distinct. Thus, it can be safely used with FileLinesCollection.

        Parameters:
        blockSizeInBytes - the block size (in bytes).
        terms - a collection whose iterator will enumerate in lexicographical order the terms for the map.
        Throws:
        IOException
      • ImmutableExternalPrefixMap

        public ImmutableExternalPrefixMap​(Iterable<? extends CharSequence> terms)
                                   throws IOException
        Creates an external prefix map with block size STD_BLOCK_SIZE.

        This constructor does not assume that strings returned by terms.iterator() will be distinct. Thus, it can be safely used with FileLinesCollection.

        Parameters:
        terms - a collection whose iterator will enumerate in lexicographical order the terms for the map.
        Throws:
        IOException
    • Method Detail

      • setDumpStream

        public void setDumpStream​(CharSequence dumpStreamFilename)
                           throws FileNotFoundException
        Sets the dump stream of this external prefix map to a given filename.

        This method sets the dump file used by this map, and should be only called after deserialisation, providing exactly the file generated at creation time. Essentially anything can happen if you do not follow the rules.

        Note that this method will attempt to close the old stream, if present.

        Parameters:
        dumpStreamFilename - the name of the dump file.
        Throws:
        FileNotFoundException
        See Also:
        setDumpStream(InputBitStream)
      • setDumpStream

        public void setDumpStream​(InputBitStream dumpStream)
        Sets the dump stream of this external prefix map to a given input bit stream.

        This method sets the dump file used by this map, and should be only called after deserialisation, providing a repositionable stream containing exactly the file generated at creation time. Essentially anything can happen if you do not follow the rules.

        Using this method you can load an external prefix map in core memory, enjoying the compactness of the data structure, but getting much more speed.

        Note that this method will attemp to close the old stream, if present.

        Parameters:
        dumpStream - a repositionable input bit stream containing exactly the dump stream generated at creation time.
        See Also:
        setDumpStream(CharSequence)
      • iterator

        public ObjectIterator<CharSequence> iterator()
        Returns an iterator over the map.

        The iterator returned by this method scans directly the dump stream.

        Note that the returned iterator uses the same stream as all get methods. Calling such methods while the iterator is being used will produce an IllegalStateException.

        Returns:
        an iterator over the map that just scans the dump stream.
      • size64

        public long size64()
        Description copied from interface: StringMap
        Returns the intended number of keys in this function, or -1 if no such number exists.

        Most function implementations will have some knowledge of the intended number of keys in their domain. In some cases, however, this might not be possible. This default implementation, in particular, returns -1.

        Specified by:
        size64 in interface Size64
        Specified by:
        size64 in interface StringMap<MutableString>
        Returns:
        the intended number of keys in this function, or -1 if that number is not available.