Documentation
¶
Overview ¶
Package javacompat contains the small parts of the Java runtime whose exact behavior is observable in ELK layouts.
Index ¶
- func BooleanHashCode(value bool) int32
- func DoubleCompare(a, b float64) int
- func DoubleHashCode(value float64) int32
- func DoubleToInt(value float64) int32
- func DoubleToLong(value float64) int64
- func DoubleToLongBits(value float64) uint64
- func FloatCompare(a, b float32) int
- func FloatHashCode(value float32) int32
- func FloatToIntBits(value float32) uint32
- func GWTStableSort[T any](values []T, compare func(T, T) int)
- func HashMapSpread(hash int32) int32
- func IntCompare(a, b int32) int
- func IntToByte(value int32) int8
- func IntToChar(value int32) uint16
- func IntToShort(value int32) int16
- func JSMathCos(x float64) float64
- func JSMathSin(x float64) float64
- func LongCompare(a, b int64) int
- func LongHashCode(value int64) int32
- func MathMaxDouble(a, b float64) float64
- func MathMinDouble(a, b float64) float64
- func MathRoundDouble(value float64) int64
- func MathRoundFloat(value float32) int32
- func StringHashCode(value string) int32
- func UnsignedRightShiftInt(value int32, distance uint) int32
- func UnsignedRightShiftLong(value int64, distance uint) int64
- type Comparator
- type GWTPriorityQueue
- func (queue *GWTPriorityQueue[T]) Add(item T)
- func (queue *GWTPriorityQueue[T]) AddAll(items []T) bool
- func (queue *GWTPriorityQueue[T]) IsEmpty() bool
- func (queue *GWTPriorityQueue[T]) Len() int
- func (queue *GWTPriorityQueue[T]) Offer(item T) bool
- func (queue *GWTPriorityQueue[T]) Peek() (T, bool)
- func (queue *GWTPriorityQueue[T]) Poll() (T, bool)
- type IdentityMap
- func (m *IdentityMap[K, V]) Clear()
- func (m *IdentityMap[K, V]) ContainsKey(key K) bool
- func (m *IdentityMap[K, V]) Get(key K) (V, bool)
- func (m *IdentityMap[K, V]) IsEmpty() bool
- func (m *IdentityMap[K, V]) Keys() []K
- func (m *IdentityMap[K, V]) Len() int
- func (m *IdentityMap[K, V]) Put(key K, value V) (V, bool)
- func (m *IdentityMap[K, V]) Range(visit func(K, V) bool)
- func (m *IdentityMap[K, V]) Remove(key K) (V, bool)
- func (m *IdentityMap[K, V]) Values() []V
- type IdentitySet
- func (s *IdentitySet[K]) Add(value K) bool
- func (s *IdentitySet[K]) Clear()
- func (s *IdentitySet[K]) Contains(value K) bool
- func (s *IdentitySet[K]) IsEmpty() bool
- func (s *IdentitySet[K]) Len() int
- func (s *IdentitySet[K]) Range(visit func(K) bool)
- func (s *IdentitySet[K]) Remove(value K) bool
- func (s *IdentitySet[K]) Values() []K
- type OrderedMap
- func (m *OrderedMap[K, V]) Clear()
- func (m *OrderedMap[K, V]) ContainsKey(key K) bool
- func (m *OrderedMap[K, V]) First() (K, V, bool)
- func (m *OrderedMap[K, V]) Get(key K) (V, bool)
- func (m *OrderedMap[K, V]) IsEmpty() bool
- func (m *OrderedMap[K, V]) Keys() []K
- func (m *OrderedMap[K, V]) Last() (K, V, bool)
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) Put(key K, value V) (V, bool)
- func (m *OrderedMap[K, V]) PutIfAbsent(key K, value V) (V, bool)
- func (m *OrderedMap[K, V]) Range(visit func(K, V) bool)
- func (m *OrderedMap[K, V]) Remove(key K) (V, bool)
- func (m *OrderedMap[K, V]) Values() []V
- type OrderedSet
- func (s *OrderedSet[T]) Add(value T) bool
- func (s *OrderedSet[T]) Clear()
- func (s *OrderedSet[T]) Contains(value T) bool
- func (s *OrderedSet[T]) IsEmpty() bool
- func (s *OrderedSet[T]) Len() int
- func (s *OrderedSet[T]) Range(visit func(T) bool)
- func (s *OrderedSet[T]) Remove(value T) bool
- func (s *OrderedSet[T]) Values() []T
- type PriorityQueue
- func (q *PriorityQueue[T]) Add(item T)
- func (q *PriorityQueue[T]) Clear()
- func (q *PriorityQueue[T]) Elements() []T
- func (q *PriorityQueue[T]) IsEmpty() bool
- func (q *PriorityQueue[T]) Len() int
- func (q *PriorityQueue[T]) Offer(item T) bool
- func (q *PriorityQueue[T]) Peek() (T, bool)
- func (q *PriorityQueue[T]) Poll() (T, bool)
- func (q *PriorityQueue[T]) RemoveFirst(match func(T) bool) bool
- type Random
- func (r *Random) NextBoolean() bool
- func (r *Random) NextBytes(dst []byte)
- func (r *Random) NextDouble() float64
- func (r *Random) NextFloat() float32
- func (r *Random) NextGaussian() float64
- func (r *Random) NextInt() int32
- func (r *Random) NextIntN(bound int32) int32
- func (r *Random) NextLong() int64
- func (r *Random) SetSeed(seed int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BooleanHashCode ¶
BooleanHashCode implements Boolean.hashCode(boolean).
func DoubleCompare ¶
DoubleCompare implements Double.compare. In particular, -0.0 sorts before +0.0 and every NaN sorts after positive infinity and compares equal to every other NaN.
func DoubleHashCode ¶
DoubleHashCode implements Double.hashCode(double).
func DoubleToInt ¶
DoubleToInt and DoubleToLong implement Java's narrowing primitive casts: NaN becomes zero, finite out-of-range values and infinities saturate, and finite in-range values truncate toward zero.
func DoubleToLong ¶
func DoubleToLongBits ¶
DoubleToLongBits implements Double.doubleToLongBits, including NaN canonicalization. Use math.Float64bits when Java's doubleToRawLongBits is specifically required.
func FloatHashCode ¶
FloatHashCode implements Float.hashCode(float).
func FloatToIntBits ¶
FloatToIntBits implements Float.floatToIntBits, including NaN canonicalization.
func GWTStableSort ¶ added in v0.2.0
GWTStableSort reproduces the object-array legacy merge sort in GWT 2.11.0's emulated java.util.Arrays. The relevant implementation is unchanged from GWT 2.9.0. Comparator invocation order is observable when a comparator records comparisons or derives transitive state, as ELK's model-order comparators do.
func HashMapSpread ¶
HashMapSpread reproduces the one-step high-bit spread observed by ELK's Java-compatible hash tables. Its behavior is pinned by independent vectors.
func IntCompare ¶
IntCompare and LongCompare implement Integer.compare and Long.compare.
func IntToShort ¶
func JSMathSin ¶ added in v0.2.0
JSMathSin and JSMathCos reproduce the fdlibm implementation used by V8's Math.sin and Math.cos for the medium-size arguments emitted by ELK Radial. The kernels and constants are adapted from Node.js v24.19.0's pinned V8 deps/v8/src/base/ieee754.cc (itself adapted from fdlibm). Very large arguments fall back to Go's math package; layout angles are many orders of magnitude below that boundary.
func LongCompare ¶
func LongHashCode ¶
LongHashCode implements Long.hashCode(long).
func MathMaxDouble ¶
func MathMinDouble ¶
MathMinDouble and MathMaxDouble preserve Java's NaN and signed-zero rules.
func MathRoundDouble ¶
MathRoundDouble and MathRoundFloat implement Math.round.
func MathRoundFloat ¶
func StringHashCode ¶
StringHashCode implements String.hashCode over Java UTF-16 code units, not Unicode code points. This distinction matters for supplementary characters.
func UnsignedRightShiftInt ¶
UnsignedRightShiftInt and UnsignedRightShiftLong implement Java's >>>. Java masks the shift distance to five or six bits respectively.
func UnsignedRightShiftLong ¶
Types ¶
type Comparator ¶
Comparator has the contract of java.util.Comparator.compare: negative when a is less than b, zero when they compare equal, and positive otherwise.
type GWTPriorityQueue ¶
type GWTPriorityQueue[T any] struct { // contains filtered or unexported fields }
GWTPriorityQueue reproduces GWT 2.11.0's java.util.PriorityQueue implementation linked into elkjs 0.12.0. The relevant GWT source is unchanged from the 2.9.0 runtime used by the former elkjs 0.8.2 baseline. Its bulk-add heapification and equal-item sift-down behavior differ observably from OpenJDK's PriorityQueue.
func NewGWTPriorityQueue ¶
func NewGWTPriorityQueue[T any](compare Comparator[T]) *GWTPriorityQueue[T]
func (*GWTPriorityQueue[T]) Add ¶
func (queue *GWTPriorityQueue[T]) Add(item T)
func (*GWTPriorityQueue[T]) AddAll ¶
func (queue *GWTPriorityQueue[T]) AddAll(items []T) bool
AddAll appends the complete collection and then invokes GWT's recursive makeHeap routine. It does not repeatedly call Offer.
func (*GWTPriorityQueue[T]) IsEmpty ¶
func (queue *GWTPriorityQueue[T]) IsEmpty() bool
func (*GWTPriorityQueue[T]) Len ¶
func (queue *GWTPriorityQueue[T]) Len() int
func (*GWTPriorityQueue[T]) Offer ¶
func (queue *GWTPriorityQueue[T]) Offer(item T) bool
func (*GWTPriorityQueue[T]) Peek ¶
func (queue *GWTPriorityQueue[T]) Peek() (T, bool)
func (*GWTPriorityQueue[T]) Poll ¶
func (queue *GWTPriorityQueue[T]) Poll() (T, bool)
type IdentityMap ¶
type IdentityMap[K comparable, V any] struct { // contains filtered or unexported fields }
IdentityMap provides IdentityHashMap equality semantics for identity-bearing comparable keys. K should be a pointer or an arena handle, never a value object whose == operation represents structural equality. Iteration is made deterministic in first-insertion order; ELK does not rely on the unspecified table order of java.util.IdentityHashMap.
The zero value is ready to use.
func NewIdentityMap ¶
func NewIdentityMap[K comparable, V any]() *IdentityMap[K, V]
func (*IdentityMap[K, V]) Clear ¶
func (m *IdentityMap[K, V]) Clear()
func (*IdentityMap[K, V]) ContainsKey ¶
func (m *IdentityMap[K, V]) ContainsKey(key K) bool
func (*IdentityMap[K, V]) Get ¶
func (m *IdentityMap[K, V]) Get(key K) (V, bool)
func (*IdentityMap[K, V]) IsEmpty ¶
func (m *IdentityMap[K, V]) IsEmpty() bool
func (*IdentityMap[K, V]) Keys ¶
func (m *IdentityMap[K, V]) Keys() []K
func (*IdentityMap[K, V]) Len ¶
func (m *IdentityMap[K, V]) Len() int
func (*IdentityMap[K, V]) Put ¶
func (m *IdentityMap[K, V]) Put(key K, value V) (V, bool)
func (*IdentityMap[K, V]) Range ¶
func (m *IdentityMap[K, V]) Range(visit func(K, V) bool)
func (*IdentityMap[K, V]) Remove ¶
func (m *IdentityMap[K, V]) Remove(key K) (V, bool)
func (*IdentityMap[K, V]) Values ¶
func (m *IdentityMap[K, V]) Values() []V
type IdentitySet ¶
type IdentitySet[K comparable] struct { // contains filtered or unexported fields }
IdentitySet is IdentityMap's set counterpart. K should be a pointer or an arena handle so Go equality is object identity.
func NewIdentitySet ¶
func NewIdentitySet[K comparable]() *IdentitySet[K]
func (*IdentitySet[K]) Add ¶
func (s *IdentitySet[K]) Add(value K) bool
func (*IdentitySet[K]) Clear ¶
func (s *IdentitySet[K]) Clear()
func (*IdentitySet[K]) Contains ¶
func (s *IdentitySet[K]) Contains(value K) bool
func (*IdentitySet[K]) IsEmpty ¶
func (s *IdentitySet[K]) IsEmpty() bool
func (*IdentitySet[K]) Len ¶
func (s *IdentitySet[K]) Len() int
func (*IdentitySet[K]) Range ¶
func (s *IdentitySet[K]) Range(visit func(K) bool)
func (*IdentitySet[K]) Remove ¶
func (s *IdentitySet[K]) Remove(value K) bool
func (*IdentitySet[K]) Values ¶
func (s *IdentitySet[K]) Values() []K
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is an insertion-ordered map matching LinkedHashMap's default (accessOrder=false) behavior. Replacing a value does not move its key; removing and reinserting a key appends it at the end.
The zero value is ready to use.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
NewOrderedMap constructs an empty insertion-ordered map.
func (*OrderedMap[K, V]) ContainsKey ¶
func (m *OrderedMap[K, V]) ContainsKey(key K) bool
ContainsKey reports whether key is present.
func (*OrderedMap[K, V]) First ¶
func (m *OrderedMap[K, V]) First() (K, V, bool)
First returns the oldest entry.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (V, bool)
Get looks up a value.
func (*OrderedMap[K, V]) IsEmpty ¶
func (m *OrderedMap[K, V]) IsEmpty() bool
IsEmpty reports whether the map has no entries.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() []K
Keys returns keys in insertion order.
func (*OrderedMap[K, V]) Last ¶
func (m *OrderedMap[K, V]) Last() (K, V, bool)
Last returns the newest entry.
func (*OrderedMap[K, V]) Len ¶
func (m *OrderedMap[K, V]) Len() int
Len returns the number of entries.
func (*OrderedMap[K, V]) Put ¶
func (m *OrderedMap[K, V]) Put(key K, value V) (V, bool)
Put inserts or replaces a value. It returns the old value and whether the key was already present.
func (*OrderedMap[K, V]) PutIfAbsent ¶
func (m *OrderedMap[K, V]) PutIfAbsent(key K, value V) (V, bool)
PutIfAbsent inserts only when key is absent and returns the existing or new value plus whether an existing entry was found.
func (*OrderedMap[K, V]) Range ¶
func (m *OrderedMap[K, V]) Range(visit func(K, V) bool)
Range visits entries in insertion order until visit returns false. Structural mutation during Range is unsupported, matching Java iterator fail-fast semantics without exposing a concurrent-modification exception.
func (*OrderedMap[K, V]) Remove ¶
func (m *OrderedMap[K, V]) Remove(key K) (V, bool)
Remove deletes key, preserving the relative order of all remaining keys.
func (*OrderedMap[K, V]) Values ¶
func (m *OrderedMap[K, V]) Values() []V
Values returns values in key insertion order.
type OrderedSet ¶
type OrderedSet[T comparable] struct { // contains filtered or unexported fields }
OrderedSet is an insertion-ordered set matching LinkedHashSet. The zero value is ready to use.
func NewOrderedSet ¶
func NewOrderedSet[T comparable]() *OrderedSet[T]
NewOrderedSet constructs an empty insertion-ordered set.
func (*OrderedSet[T]) Add ¶
func (s *OrderedSet[T]) Add(value T) bool
Add inserts value and reports whether the set changed.
func (*OrderedSet[T]) Contains ¶
func (s *OrderedSet[T]) Contains(value T) bool
Contains reports whether value is present.
func (*OrderedSet[T]) IsEmpty ¶
func (s *OrderedSet[T]) IsEmpty() bool
IsEmpty reports whether the set is empty.
func (*OrderedSet[T]) Range ¶
func (s *OrderedSet[T]) Range(visit func(T) bool)
Range visits values in insertion order until visit returns false.
func (*OrderedSet[T]) Remove ¶
func (s *OrderedSet[T]) Remove(value T) bool
Remove deletes value and reports whether the set changed.
func (*OrderedSet[T]) Values ¶
func (s *OrderedSet[T]) Values() []T
Values returns values in insertion order.
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
PriorityQueue is a clean-room binary min-heap whose tie behavior is pinned by elkjs oracle vectors. Java does not define FIFO ordering for equal elements, but ELK observes the heap-array order, so left-child and strict-comparison choices are part of this compatibility type's tested behavior.
func NewPriorityQueue ¶
func NewPriorityQueue[T any](compare Comparator[T]) *PriorityQueue[T]
NewPriorityQueue returns an empty Java-compatible min-priority queue.
func NewPriorityQueueCapacity ¶
func NewPriorityQueueCapacity[T any](capacity int, compare Comparator[T]) *PriorityQueue[T]
NewPriorityQueueCapacity is NewPriorityQueue with a capacity hint. Java's growth policy does not affect heap order, but avoiding reallocations is handy for the larger layered-layout queues.
func (*PriorityQueue[T]) Add ¶
func (q *PriorityQueue[T]) Add(item T)
Add inserts item. Java's add and offer have identical heap behavior.
func (*PriorityQueue[T]) Clear ¶
func (q *PriorityQueue[T]) Clear()
Clear removes every element while releasing references held by the backing slice.
func (*PriorityQueue[T]) Elements ¶
func (q *PriorityQueue[T]) Elements() []T
Elements returns a copy in PriorityQueue iterator order (the heap-array order). This order is deliberately not sorted, just like Java's iterator.
func (*PriorityQueue[T]) IsEmpty ¶
func (q *PriorityQueue[T]) IsEmpty() bool
IsEmpty reports whether the queue is empty.
func (*PriorityQueue[T]) Len ¶
func (q *PriorityQueue[T]) Len() int
Len returns the number of queued elements.
func (*PriorityQueue[T]) Offer ¶
func (q *PriorityQueue[T]) Offer(item T) bool
Offer inserts item and returns true, matching PriorityQueue.offer.
func (*PriorityQueue[T]) Peek ¶
func (q *PriorityQueue[T]) Peek() (T, bool)
Peek returns the least element without removing it.
func (*PriorityQueue[T]) Poll ¶
func (q *PriorityQueue[T]) Poll() (T, bool)
Poll removes and returns the least element.
func (*PriorityQueue[T]) RemoveFirst ¶
func (q *PriorityQueue[T]) RemoveFirst(match func(T) bool) bool
RemoveFirst removes the first element in the queue's internal array for which match returns true. This is PriorityQueue.remove(Object) with equality supplied explicitly, which also supports non-comparable Go values.
type Random ¶
type Random struct {
// contains filtered or unexported fields
}
Random is a bit-for-bit implementation of java.util.Random from Java 8.
Random is not safe for concurrent use. ELK owns one instance per layout, as the Java implementation does, so synchronization would only obscure the order in which random values are consumed.
func (*Random) NextBoolean ¶
NextBoolean implements Random.nextBoolean().
func (*Random) NextBytes ¶
NextBytes implements Random.nextBytes(byte[]). Java's byte is signed, but assigning its low eight bits to a Go byte gives the same byte sequence.
func (*Random) NextDouble ¶
NextDouble implements Random.nextDouble().
func (*Random) NextGaussian ¶
NextGaussian implements Random.nextGaussian(), including its cached second sample. ELK 0.8.1 does not use this in a layout path, but providing the Java behavior prevents consumers from accidentally substituting math/rand. Math-library results may differ by a final bit across platforms, just as Java's Math implementation may, while the random-value consumption is exact.
func (*Random) NextIntN ¶
NextIntN implements Random.nextInt(bound). It panics for a non-positive bound, corresponding to Java's IllegalArgumentException.