Class ASet<T extends ACell>

Type Parameters:
T - Type of set elements
All Implemented Interfaces:
IAssociative<T,​CVMBool>, IValidated, IWriteable, Iterable<T>, Collection<T>, Set<T>
Direct Known Subclasses:
AHashSet

public abstract class ASet<T extends ACell> extends ACollection<T> implements Set<T>, IAssociative<T,​CVMBool>
Abstract based class for sets. Sets are immutable Smart Data Structures representing an unordered collection of distinct values. Iteration order is dependent on the Set implementation. In general, it is bad practice to depend on any specific ordering for sets.
  • Constructor Details

    • ASet

      protected ASet(long count)
  • Method Details

    • getType

      public final AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Specified by:
      getType in class ACollection<T extends ACell>
      Returns:
      The Type of this Call
    • getTag

      public final byte getTag()
      Description copied from class: ACell
      Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding
      Specified by:
      getTag in class ACell
      Returns:
      Tag byte for this Cell
    • include

      public abstract <R extends ACell> ASet<R> include(R a)
      Updates the set to include the given element
      Parameters:
      a - Value to include
      Returns:
      Updated set
    • exclude

      public abstract ASet<T> exclude(T a)
      Updates the set to exclude the given element
      Parameters:
      a - Value to exclude
      Returns:
      Updated set
    • includeAll

      public abstract <R extends ACell> ASet<R> includeAll(ASet<R> elements)
      Updates the set to include all the given elements. Can be used to implement union of sets
      Parameters:
      elements - Elements to include
      Returns:
      Updated set
    • excludeAll

      public abstract ASet<T> excludeAll(ASet<T> elements)
      Updates the set to exclude all the given elements.
      Parameters:
      elements - Elements to exclude
      Returns:
      Updated set
    • conjAll

      public abstract <R extends ACell> ASet<R> conjAll(ACollection<R> xs)
      Description copied from class: ADataStructure
      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.
      Overrides:
      conjAll in class ADataStructure<T extends ACell>
      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
    • disjAll

      public abstract ASet<T> disjAll(ACollection<T> xs)
      Removes all elements from this set, returning a new set.
      Parameters:
      xs - Collection of elements to remove
      Returns:
      Set with specified element(s) removed
    • toVector

      public <R extends ACell> AVector<R> toVector()
      Description copied from class: ACollection
      Converts this collection to a canonical vector of elements
      Specified by:
      toVector in class ACollection<T extends ACell>
      Returns:
      This collection coerced to a vector
    • map

      public <R extends ACell> ASet<R> map(Function<? super T,​? extends R> mapper)
      Description copied from class: ACollection
      Maps a function over a collection, applying it to each element in turn.
      Specified by:
      map in class ACollection<T extends ACell>
      Type Parameters:
      R - Type of element in resulting collection
      Parameters:
      mapper - Function to map over collection
      Returns:
      Collection after function applied to each element
    • intersectAll

      public abstract ASet<T> intersectAll(ASet<T> xs)
      Returns the intersection of two sets
      Parameters:
      xs - Set to intersect with
      Returns:
      Intersection of the two sets
    • get

      public CVMBool get(ACell key)
      Description copied from class: ADataStructure
      Get the value associated with a given key.
      Specified by:
      get in class ADataStructure<T extends ACell>
      Parameters:
      key - Associative key to look up
      Returns:
      Value from collection, or a falsey value (null or false) if not found
    • get

      public ACell get(ACell key, ACell notFound)
      Description copied from class: ADataStructure
      Get the value associated with a given key.
      Specified by:
      get in class ADataStructure<T extends ACell>
      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
    • get

      public T get(long index)
      Description copied from class: ACountable
      Gets the element at the specified index in this collection
      Specified by:
      get in class ACountable<T extends ACell>
      Parameters:
      index - Index of element to get
      Returns:
      Element at the specified index
    • contains

      public abstract boolean contains(ACell o)
      Tests if this Set contains a given value
      Parameters:
      o - Value to test for set membership
      Returns:
      True if set contains value, false otherwise
    • contains

      public final boolean contains(Object o)
      Specified by:
      contains in interface Collection<T extends ACell>
      Specified by:
      contains in interface Set<T extends ACell>
      Specified by:
      contains in class ACollection<T extends ACell>
    • equals

      public final boolean equals(ACell o)
      Description copied from class: ACell
      Checks for equality with another object. In general, data objects should be considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses should override this if they have a more efficient equals implementation.
      Overrides:
      equals in class ACell
      Parameters:
      o - Cell to compare with. May be null??
      Returns:
      True if this cell is equal to the other object
    • equals

      public abstract boolean equals(ASet<T> other)
      Checks if another set is exactly equal to this set
      Parameters:
      other - Set to compare with this set
      Returns:
      true if sets are equal, false otherwise
    • includeRef

      public abstract ASet<T> includeRef(Ref<T> ref)
      Adds a value to this set using a Ref to the value
      Parameters:
      ref - Ref to value to include
      Returns:
      Updated set
    • conj

      public abstract <R extends ACell> ASet<R> conj(R a)
      Description copied from class: ACollection
      Adds an element to this collection, according to the natural semantics of the collection
      Specified by:
      conj in class ACollection<T extends ACell>
      Type Parameters:
      R - Type of Value added
      Parameters:
      a - Value to add
      Returns:
      The updated collection
    • assoc

      public ASet<T> assoc(ACell key, ACell value)
      Description copied from class: ADataStructure
      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.
      Specified by:
      assoc in class ADataStructure<T extends ACell>
      Parameters:
      key - Associative key
      value - Value to associate with key
      Returns:
      Updates data structure, or null if data types are invalid
    • containsKey

      public boolean containsKey(ACell key)
      Description copied from class: ADataStructure
      Checks if the data structure contains the specified key
      Specified by:
      containsKey in class ADataStructure<T extends ACell>
      Parameters:
      key - Associative key to look up
      Returns:
      true if the data structure contains the key, false otherwise
    • empty

      public ASet<T> empty()
      Description copied from class: ADataStructure
      Returns an empty instance of the same general type as this data structure.
      Specified by:
      empty in class ADataStructure<T extends ACell>
      Returns:
      An empty data structure
    • getValueRef

      public abstract Ref<T> getValueRef(ACell k)
      Gets the Ref in the Set for a given value, or null if not found
      Parameters:
      k - Value to check for set membership
      Returns:
      Ref to value, or null
    • getRefByHash

      protected abstract Ref<T> getRefByHash(Hash hash)
      Gets the Ref in the Set for a given hash, or null if not found
      Parameters:
      hash - Hash to check for set membership
      Returns:
      Ref to value with given Hash, or null
    • containsAll

      public abstract boolean containsAll(ASet<T> b)
      Tests if this set contains all the elements of another set
      Parameters:
      b - Set to compare with
      Returns:
      True if other set is completely contained within this set, false otherwise
    • isSubset

      public boolean isSubset(ASet<T> b)
      Tests if this set is a (non-strict) subset of another Set
      Parameters:
      b - Set to test against
      Returns:
      True if this is a subset of the other set, false otherwise.
    • print

      public void print(StringBuilder sb)
      Description copied from class: AObject
      Prints this Object to a readable String Representation
      Specified by:
      print in class AObject
      Parameters:
      sb - StringBuilder to append to