Class BinVal

  • All Implemented Interfaces:
    Comparable<BinVal>, HostResult

    public class BinVal
    extends Val
    implements Comparable<BinVal>
    A bin val, which represents an immutable array of bytes.

    A bin val holds Java byte arrays as a binary tree in order to avoid allocation of the entire array on concatenation. The byte array is substantiated on demand.

    • Method Detail

      • size

        public int size()
        Returns the size of the bin.
        Returns:
        the size of the bin.
      • getBytes

        public byte[] getBytes()
        Returns the copied bytes of the bin.
        Returns:
        the copied bytes of the bin.
      • get

        public byte get​(int ind)
        Returns the byte at the ind.
        Parameters:
        ind - the index of the byte.
        Returns:
        the byte at the ind.
        Throws:
        IndexOutOfBoundsException - if ind is out of the range of the bin.
      • slice

        public BinVal slice​(int from,
                            int to)
        Returns a sliced bin between from (inclusive) and to (exclusive).
        Parameters:
        from - the inclusive index where the result is sliced from.
        to - the exclusive index where the result is sliced to.
        Returns:
        a sliced bin.
        Throws:
        IndexOutOfBoundsException - if from or to are out of the range of the bin.
        IllegalArgumentException - if from is larger than to.
      • compareTo

        public int compareTo​(BinVal arg)
        Returns a negative number if this is less than arg, 0 if this is equivalent to arg, or a positive number if this is greater than arg.

        Comparison is done for the bytes of this and arg, treating the bytes as unsigned numbers.

        Comparison is agnostic with vm field.

        Specified by:
        compareTo in interface Comparable<BinVal>
        Parameters:
        arg - the arg bin to compare with.
        Returns:
        the comparison number.
      • concat

        public BinVal concat​(BinVal tail)
        Returns a bin val which concatenates this and tail.
        Parameters:
        tail - the bin which is appended to the result.
        Returns:
        a bin val which concatenates this and tail.
      • equals

        public boolean equals​(Object arg)
        Returns true if and only if arg is a bin val and has the same vm and the equivalent bytes with this.
        Overrides:
        equals in class Object
        Parameters:
        arg - the arg object to compare with.
        Returns:
        true if and only if arg is a bin val and has the same vm and the equivalent bytes with this.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object