Class BookPrimitives

java.lang.Object
com.quantfinlib.orderbook.BookPrimitives

public final class BookPrimitives extends Object
The zero-allocation building blocks shared by the hot-lane books (HftOrderBook venue-side, marketdata.L3BookBuilder participant-side): occupancy-bitmap scans and a primitive open-addressing long→int map with backward-shift deletion. Static methods over caller-owned arrays — invokestatic with no receiver, so sharing costs nothing on the hot path and the subtlest code in the library (the circular probe-order rule in mapRemoveAt(long[], int[], int, int)) exists exactly once.

Map convention: key 0 is the empty-slot sentinel (both books use strictly positive ids/refs); capacity is a power of two with mask = capacity - 1 and load factor ≤ 0.5. Scans return -1 for "none".

  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    mapFind(long[] keys, int mask, long key)
    Slot of key, or -1.
    static void
    mapPut(long[] keys, int[] vals, int mask, long key, int value)
    Inserts into the open-addressing map (caller guarantees the key is absent).
    static void
    mapRemoveAt(long[] keys, int[] vals, int mask, int slot)
    Backward-shift deletion: re-places every entry of the probe run that follows the hole, so lookups never need tombstones and cancel churn cannot degrade probe lengths over a long session.
    static long
    mix(long z)
    Stafford variant 13 finalizer: cheap, well-mixed long hash.
    static int
    nextSetAtOrAbove(long[] bits, int from)
    Lowest set bit at or above from, or -1.
    static int
    nextSetAtOrBelow(long[] bits, int from)
    Highest set bit at or below from, or -1.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • nextSetAtOrAbove

      public static int nextSetAtOrAbove(long[] bits, int from)
      Lowest set bit at or above from, or -1. Bits past the ladder must be clear.
    • nextSetAtOrBelow

      public static int nextSetAtOrBelow(long[] bits, int from)
      Highest set bit at or below from, or -1.
    • mapPut

      public static void mapPut(long[] keys, int[] vals, int mask, long key, int value)
      Inserts into the open-addressing map (caller guarantees the key is absent).
    • mapFind

      public static int mapFind(long[] keys, int mask, long key)
      Slot of key, or -1.
    • mapRemoveAt

      public static void mapRemoveAt(long[] keys, int[] vals, int mask, int slot)
      Backward-shift deletion: re-places every entry of the probe run that follows the hole, so lookups never need tombstones and cancel churn cannot degrade probe lengths over a long session.
    • mix

      public static long mix(long z)
      Stafford variant 13 finalizer: cheap, well-mixed long hash.