Class DynamicSectionContainer<S extends Tracked<K>,K extends WorldKey>

java.lang.Object
net.paulem.arcana.regions.container.blocks.DynamicSectionContainer<S,K>
Type Parameters:
S - the type of tracked objects, which must implement the Tracked interface
K - the type of the key associated with the tracked object
All Implemented Interfaces:
SectionContainer<S,K>

public class DynamicSectionContainer<S extends Tracked<K>,K extends WorldKey> extends Object implements SectionContainer<S,K>
A container implementation that dynamically transitions between a MapContainer and an ArraySectionContainer based on the load factor and size constraints. This class is designed to optimize memory usage and performance by starting with an efficient map-based container and expanding into an array-based container when necessary.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <S extends Tracked<K>, K extends WorldKey>
    DynamicSectionContainer<S,K>
    create(float loadFactor, int maxSize)
    Creates a new DynamicSectionContainer with the given load factor and capacity.
    static <S extends Tracked<K>, K extends WorldKey>
    DynamicSectionContainer<S,K>
    create(int maxSize)
    Creates a new DynamicSectionContainer with the given capacity and the default load factor.
    get(int position)
    Retrieves the holder at the given position from the currently active underlying container.
    it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<Holder<S,K>>
     
    void
    Copies every entry from the given container into this one, expanding to an array-backed container first if adding them would exceed the load factor.
    void
    set(int position, Holder<S,K> holder)
    Stores or clears the holder at the given position in the currently active underlying container, expanding to an array-backed container first if the load factor is now exceeded.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.paulem.arcana.regions.container.blocks.SectionContainer

    copyTo, isEmpty, size
  • Method Details

    • create

      public static <S extends Tracked<K>, K extends WorldKey> DynamicSectionContainer<S,K> create(float loadFactor, int maxSize)
      Creates a new DynamicSectionContainer with the given load factor and capacity.
      Type Parameters:
      S - the type of tracked objects
      K - the type of the key associated with the tracked object
      Parameters:
      loadFactor - the fraction of maxSize that, once reached, triggers expansion to an array-backed container
      maxSize - the maximum number of positions this container can hold once expanded
      Returns:
      a new DynamicSectionContainer instance
    • create

      public static <S extends Tracked<K>, K extends WorldKey> DynamicSectionContainer<S,K> create(int maxSize)
      Creates a new DynamicSectionContainer with the given capacity and the default load factor.
      Type Parameters:
      S - the type of tracked objects
      K - the type of the key associated with the tracked object
      Parameters:
      maxSize - the maximum number of positions this container can hold once expanded
      Returns:
      a new DynamicSectionContainer instance
    • get

      public Holder<S,K> get(int position)
      Retrieves the holder at the given position from the currently active underlying container.
      Specified by:
      get in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Parameters:
      position - the index to look up
      Returns:
      the holder at the position, or null if empty
    • set

      public void set(int position, Holder<S,K> holder)
      Stores or clears the holder at the given position in the currently active underlying container, expanding to an array-backed container first if the load factor is now exceeded.
      Specified by:
      set in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Parameters:
      position - the index to store the holder at
      holder - the holder to store, or null to clear the position
    • getAll

      public it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<Holder<S,K>> getAll()
      Specified by:
      getAll in interface SectionContainer<S extends Tracked<K>,K extends WorldKey>
      Returns:
      a map of position to holder for every non-null entry in the currently active underlying container
    • putAll

      public void putAll(SectionContainer<S,K> other)
      Copies every entry from the given container into this one, expanding to an array-backed container first if adding them would exceed the load factor.
      Parameters:
      other - the container whose entries should be copied into this one