LongMap

org.saddle.util.LongMap
See theLongMap companion object
final class LongMap(defaultEntry: Long => Int, initialBufferSize: Int, initBlank: Boolean)

This class implements mutable maps with Long keys based on a hash table with open addressing.

Basic map operations on single entries, including contains and get, are typically substantially faster with LongMap than HashMap. Methods that act on the whole map, including foreach and map are not in general expected to be faster than with a generic map, save for those that take particular advantage of the internal structure of the map: foreachKey, foreachValue, mapValuesNow, and transformValues.

Maps with open addressing may become less efficient at lookup after repeated addition/removal of elements. Although LongMap makes a decent attempt to remain efficient regardless, calling repack on a map that will no longer have elements removed but will be used heavily may save both time and storage space.

This map is not intended to contain more than 2^29 entries (approximately 500 million). The maximum capacity is 2^30, but performance will degrade rapidly as 2^30 is approached.

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Constructors

def this()
def this(initialBufferSize: Int)

Creates a new LongMap with an initial buffer of specified size.

Creates a new LongMap with an initial buffer of specified size.

A LongMap can typically contain half as many elements as its buffer size before it requires resizing.

Attributes

def this(defaultEntry: Long => Int, initialBufferSize: Int)

Creates a new LongMap with specified default values and initial buffer size.

Creates a new LongMap with specified default values and initial buffer size.

Attributes

Concrete methods

def contains(key: Long): Boolean
def foreachKey[A](f: Long => A): Unit

Applies a function to all keys of this map.

Applies a function to all keys of this map.

Attributes

def get(key: Long): Option[Int]
def initializeTo(m: Int, ek: Int, zv: Int, mv: Int, sz: Int, vc: Int, kz: Array[Long], vz: Array[Int]): Unit
def repack(): Unit

Repacks the contents of this LongMap for maximum efficiency of lookup.

Repacks the contents of this LongMap for maximum efficiency of lookup.

For maps that undergo a complex creation process with both addition and removal of keys, and then are used heavily with no further removal of elements, calling repack after the end of the creation can result in improved performance. Repacking takes time proportional to the number of entries in the map.

Attributes

def size: Int
def update(key: Long, value: Int): Unit

Updates the map to include a new key-value pair.

Updates the map to include a new key-value pair.

This is the fastest way to add an entry to a LongMap.

Attributes