Class OdHashedImpl<T>

  • All Implemented Interfaces:
    Comparable<IdAble>, Iterable<T>, IdAble, OdData<T>, OdHashed<T>
    Direct Known Subclasses:
    OdPathsHashed

    public abstract class OdHashedImpl<T>
    extends OdDataImpl<T>
    implements OdHashed<T>
    This class stores paths by their origin and destination by creating a unique hash for the combined ids of the od zones. This results in a memory efficient implementation requiring only a single hash based container, instead of having as many containers as their are origins. It also means only conducting a single lookup despite the fact we have two keys (o and d).
    Author:
    markr
    • Field Detail

      • odHashed

        protected final HashMap<Integer,​T> odHashed
        the hashed OD values where the key is based on the combined ids of origin and destination
    • Constructor Detail

      • OdHashedImpl

        public OdHashedImpl​(Class<? extends IdAble> idClass,
                            IdGroupingToken groupId,
                            OdZones zones)
        Constructor
        Parameters:
        idClass - concrete class to use for id generation
        groupId - contiguous id generation within this group for instances of this class
        zones - the zones being used
      • OdHashedImpl

        public OdHashedImpl​(OdHashedImpl<T> other)
        Copy constructor, only shallow copy implemented, deep copy is to be implemented by parent because we do not want to enforce more type information on values
        Parameters:
        other - to copy from
    • Method Detail

      • getValue

        public T getValue​(Zone origin,
                          Zone destination)
        Returns the value for a specified origin and destination
        Specified by:
        getValue in interface OdData<T>
        Parameters:
        origin - specified origin
        destination - specified destination
        Returns:
        value at the specified cell
      • getValue

        public T getValue​(long originId,
                          long destinationId)
        Returns the value for a specified origin and destination by their internal id
        Specified by:
        getValue in interface OdData<T>
        Parameters:
        originId - specified origin
        destinationId - specified destination
        Returns:
        value at the specified cell
      • setValue

        public void setValue​(Zone origin,
                             Zone destination,
                             T path)
        Sets the value for a specified origin and destination
        Specified by:
        setValue in interface OdData<T>
        Parameters:
        origin - specified origin
        destination - specified destination
        path - value at the specified cell
      • iterator

        public abstract OdHashedIterator<T> iterator()
        Returns an iterator which can iterate through all the origin-destination entries
        Specified by:
        iterator in interface Iterable<T>
        Specified by:
        iterator in interface OdData<T>
        Specified by:
        iterator in interface OdHashed<T>
        Returns:
        iterator through all available non-empty origin-destination entries
      • deepClone

        public abstract OdHashedImpl<T> deepClone()
        An id entity should always support a deep copy, i.e., all "owned" members will be deep copied when a clone of this instance is created via this call. To be used with caution if not called by managed id container related code
        Specified by:
        deepClone in interface IdAble
        Specified by:
        deepClone in class OdDataImpl<T>
        Returns:
        deep copy of entity