- java.lang.Object
-
- org.kink_lang.kink.HostResultCore
-
- org.kink_lang.kink.Val
-
- org.kink_lang.kink.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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(BinVal arg)
Returns a negative number ifthis
is less thanarg
, 0 ifthis
is equivalent toarg
, or a positive number ifthis
is greater thanarg
.BinVal
concat(BinVal tail)
Returns a bin val which concatenatesthis
andtail
.boolean
equals(Object arg)
Returns true if and only ifarg
is a bin val and has the same vm and the equivalent bytes withthis
.byte
get(int ind)
Returns the byte at the ind.byte[]
getBytes()
Returns the copied bytes of the bin.int
hashCode()
int
size()
Returns the size of the bin.BinVal
slice(int from, int to)
Returns a sliced bin betweenfrom
(inclusive) andto
(exclusive).String
toString()
-
Methods inherited from class org.kink_lang.kink.Val
getIdentity, getVar, getVarSymHandleSet, hasVar, makeHostResultCore, setVar
-
-
-
-
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
- ifind
is out of the range of the bin.
-
slice
public BinVal slice(int from, int to)
Returns a sliced bin betweenfrom
(inclusive) andto
(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
- iffrom
orto
are out of the range of the bin.IllegalArgumentException
- iffrom
is larger thanto
.
-
compareTo
public int compareTo(BinVal arg)
Returns a negative number ifthis
is less thanarg
, 0 ifthis
is equivalent toarg
, or a positive number ifthis
is greater thanarg
.Comparison is done for the bytes of
this
andarg
, treating the bytes as unsigned numbers.Comparison is agnostic with
vm
field.- Specified by:
compareTo
in interfaceComparable<BinVal>
- Parameters:
arg
- the arg bin to compare with.- Returns:
- the comparison number.
-
concat
public BinVal concat(BinVal tail)
Returns a bin val which concatenatesthis
andtail
.- Parameters:
tail
- the bin which is appended to the result.- Returns:
- a bin val which concatenates
this
andtail
.
-
equals
public boolean equals(Object arg)
Returns true if and only ifarg
is a bin val and has the same vm and the equivalent bytes withthis
.
-
-