Class ADataStructure<E extends ACell>

Type Parameters:
E - Type of Data Structure elements
All Implemented Interfaces:
IValidated, IWriteable
Direct Known Subclasses:
ACollection, AMap

public abstract class ADataStructure<E extends ACell> extends ACountable<E>
Abstract base class for Persistent data structures. Each can be regarded as a countable, immutable collection of elements. Data structures in general support:
  • Immutability
  • Addition of an element(s) of appropriate type
  • Construction of an empty (zero) element

"When you know your data can never change out from underneath you, everything is different." - Rich Hickey

  • Field Details

    • count

      protected final long count
  • Constructor Details

    • ADataStructure

      protected ADataStructure(long count)
  • Method Details

    • count

      public final long count()
      Gets the count of elements in this data structure
      Specified by:
      count in class ACountable<E extends ACell>
      Returns:
      Number of elements in this collection.
    • size

      public final int size()
      Description copied from class: ACountable
      Gets the size of this data structure as an int. Returns Integer.MAX_SIZE if the count is larger than can fit in an int. If this might be a problem, use count() instead.
      Overrides:
      size in class ACountable<E extends ACell>
      Returns:
      Number of elements in this collection.
    • empty

      public abstract ADataStructure<E> empty()
      Returns an empty instance of the same Type as this data structure.
      Specified by:
      empty in class ACountable<E extends ACell>
      Returns:
      An empty data structure
    • isEmpty

      public final boolean isEmpty()
      Description copied from class: ACountable
      Checks if this data structure is empty, i.e. has a count of zero elements.
      Overrides:
      isEmpty in class ACountable<E extends ACell>
      Returns:
      true if this data structure is empty, false otherwise
    • conj

      public abstract <R extends ACell> ADataStructure<R> conj(R x)
      Adds an element to this data structure, in the natural manner defined by the general data structure type. e.g. append at the end of a vector.
      Type Parameters:
      R - Type of Value added
      Parameters:
      x - New element to add
      Returns:
      The updated data structure, or null if a failure occurred due to invalid element type
    • conjAll

      public <R extends ACell> ADataStructure<R> conjAll(ACollection<R> xs)
      Adds multiple elements to this data structure, in the natural manner defined by the general data structure type. e.g. append at the end of a vector. This may be more efficient than using 'conj' for individual items.
      Type Parameters:
      R - Type of Value added
      Parameters:
      xs - New elements to add
      Returns:
      The updated data structure, or null if a failure occurred due to invalid elementtypes
    • assoc

      public abstract ADataStructure<E> assoc(ACell key, ACell value)
      Associates a key with a value in this associative data structure. May return null if the Key or Value is incompatible with the data structure.
      Parameters:
      key - Associative key
      value - Value to associate with key
      Returns:
      Updates data structure, or null if data types are invalid
    • get

      public abstract ACell get(ACell key)
      Get the value associated with a given key.
      Parameters:
      key - Associative key to look up
      Returns:
      Value from collection, or a falsey value (null or false) if not found
    • get

      public abstract ACell get(ACell key, ACell notFound)
      Get the value associated with a given key.
      Parameters:
      key - Key to look up in data structure
      notFound - Value to return if key is not found
      Returns:
      Value from collection, or notFound value if not found
    • containsKey

      public abstract boolean containsKey(ACell key)
      Checks if the data structure contains the specified key
      Parameters:
      key - Associative key to look up
      Returns:
      true if the data structure contains the key, false otherwise
    • toCVMString

      public AString toCVMString(long limit)
      Converts CVM data structure to a CVM String, as per 'print'
      Overrides:
      toCVMString in class ACell
      Parameters:
      limit - Limit of CVM String length in UTF-8 bytes
      Returns:
      CVM String, or null if limit exceeded