Interface ValueIndexer<V>

Type Parameters:
V - The type of values stored in the collection.

public interface ValueIndexer<V>
A collection that stores values and assigns them a unique long identifier. The engine uses this API to store fact field values expressed as Object[].

Aside from hashing and equality, the default implementation of this interface essentially works as shown below:


 private final AtomicLong indexer = new AtomicLong(0);
 private final Map<Object[], Long> mapping = new ConcurrentHashMap<>();
 private final Map<Long, Object[]> reverse = new ConcurrentHashMap<>();

 public long getOrCreateId(Object[] fieldValues) {
     return mapping.computeIfAbsent(fieldValues, k -> {
         long id = indexer.getAndIncrement();
         reverse.put(id, k);
         return id;
     });
 }
 

When a RuleSession is created, the engine will generate as many instances of this interface as there are logical types in the ruleset. The implementations must be thread-safe.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assignId(long id, V value)
    Assigns the given value to the specified identifier.
    void
    Clears the internally stored mapping.
    delete(long id)
    Deletes the value associated with the given unique identifier.
    get(long id)
    Retrieves the value associated with the given unique identifier.
    long
    Returns the unique identifier for the specified value, creating a new one if it does not already exist.
  • Method Details

    • getOrCreateId

      long getOrCreateId(V value)
      Returns the unique identifier for the specified value, creating a new one if it does not already exist.
      Parameters:
      value - The value for which the identifier is to be retrieved or created.
      Returns:
      The unique long identifier assigned to the specified value.
    • get

      V get(long id)
      Retrieves the value associated with the given unique identifier.
      Parameters:
      id - The unique identifier for the desired value.
      Returns:
      The value associated with the specified identifier, or null if no such value exists.
    • delete

      V delete(long id)
      Deletes the value associated with the given unique identifier.
      Parameters:
      id - The unique identifier for the value to be deleted.
      Returns:
      The value that was associated with the specified identifier, or null if no such value exists.
    • assignId

      void assignId(long id, V value)
      Assigns the given value to the specified identifier.
      Parameters:
      id - The unique identifier for the value.
      value - The value to be associated with the specified identifier.
    • clear

      void clear()
      Clears the internally stored mapping.