MutableNamedEntryCollection

A specialist collection type entirely designed for use by the Js5Index class.

Entries may be accessed by their ID number or by the hash of their name, if they are named.

Entries are sorted by their ID. The IDs should be fairly dense starting around 0, as the client stores entries in an array. Nevertheless, this implementation currently supports sparse IDs efficiently as the entries are actually stored in a tree map, primarily to make manipulation of the collection simpler (the client's implementation has the luxury of being read-only!)

As the vast majority of Js5Index.Groups only have a single Js5Index.File entry, there is a special case for single entry collections. This avoids the memory overhead of the underlying collections in this special case, at the expense of making the logic slightly more complicated.

Entries without a name have a name hash of -1. This is consistent with the client, which sets the name hash array to -1 before populating it. If the index or group is sparse, any non-existent IDs still have a hash of -1, which is passed into the client's IntHashTable class. This makes -1 unusable, so I feel this choice is justified.

In practice, I think indexes generally either have names for every file or none at all, but allowing a mixture in this implementation makes mutating the index simpler.

This implementation permits multiple entries to have the same name hash. In the event of a collision, the colliding entry with the lowest ID is returned from methods that look up an entry by its name hash. This implementation still behaves correctly if one of the colliding entries is removed: it will always return the entry with the next lowest ID.

This is an edge case that is unlikely to be hit in practice: the 550 cache has no collisions, and the 876 cache only has a single collision (the hash for the empty string).

Inheritors

Constructors

Link copied to clipboard
constructor(entryConstructor: (MutableNamedEntryCollection<T>, Int) -> T)

Properties

Link copied to clipboard
open override val capacity: Int
Link copied to clipboard
open override val size: Int

Functions

Link copied to clipboard
open operator override fun contains(id: Int): Boolean
open operator fun contains(name: String): Boolean
Link copied to clipboard
open override fun containsNamed(nameHash: Int): Boolean
Link copied to clipboard
fun createOrGet(id: Int): T
fun createOrGet(name: String): T
Link copied to clipboard
fun createOrGetNamed(nameHash: Int): T
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open fun forEach(p0: Consumer<in T>)
Link copied to clipboard
open operator override fun get(id: Int): T?
open operator fun get(name: String): T?
Link copied to clipboard
open override fun getNamed(nameHash: Int): T?
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open operator override fun iterator(): MutableIterator<T>
Link copied to clipboard
fun remove(id: Int): T?
fun remove(name: String): T?
Link copied to clipboard
fun removeNamed(nameHash: Int): T?
Link copied to clipboard