java.lang.Object
com.darkcollective.relix.symbol.table.internal.InMemorySymbolTable
All Implemented Interfaces:
SymbolTable

public final class InMemorySymbolTable extends Object implements SymbolTable
An in-memory implementation of SymbolTable suitable for single-session, in-process use.

Not thread-safe. External synchronisation is required if the table is shared across threads.

Internal structure

Relations are stored in a two-level map: namespace (lower-cased) → canonicalName → RelationSymbol.

Functions are stored in a three-level map: namespace → canonicalName → parameterSignature → FunctionSymbol. The parameter signature is the ordered list of ScalarType values, which is used as a List key (equality is value-based).

Both maps use LinkedHashMap so that iteration order reflects registration order.

Shadow policy

When a symbol conflicts with an existing one, the existing symbol's ShadowPolicy is consulted:

  • Constructor Details

    • InMemorySymbolTable

      public InMemorySymbolTable()
  • Method Details

    • register

      public RegistrationResult register(Symbol symbol)
      Description copied from interface: SymbolTable
      Attempts to register symbol in the table.

      If a symbol with the same namespace and canonical name (and, for functions, the same parameter signature) already exists, the existing symbol's ShadowPolicy governs the outcome.

      Specified by:
      register in interface SymbolTable
      Parameters:
      symbol - the symbol to register; must not be null
      Returns:
      a result describing whether the symbol was accepted, warned, or rejected
    • lookupRelation

      public Optional<RelationSymbol> lookupRelation(String name)
      Description copied from interface: SymbolTable
      Returns the relation with the given name from the "default" namespace, or — if not found there — from the "builtin" namespace.
      Specified by:
      lookupRelation in interface SymbolTable
      Parameters:
      name - the relation name (case-insensitive)
      Returns:
      the matching relation symbol, or empty if none found
    • lookupRelation

      public Optional<RelationSymbol> lookupRelation(String namespace, String name)
      Description copied from interface: SymbolTable
      Returns the relation with the given name in the specified namespace.
      Specified by:
      lookupRelation in interface SymbolTable
      Parameters:
      namespace - the target namespace (case-insensitive)
      name - the relation name (case-insensitive)
      Returns:
      the matching relation symbol, or empty if none found
    • lookupFunction

      public List<FunctionSymbol> lookupFunction(String name)
      Description copied from interface: SymbolTable
      Returns all overloads of the function with the given name from the "default" namespace, then the "builtin" namespace.
      Specified by:
      lookupFunction in interface SymbolTable
      Parameters:
      name - the function name (case-insensitive)
      Returns:
      all matching function symbols; never null, may be empty
    • lookupFunction

      public List<FunctionSymbol> lookupFunction(String namespace, String name)
      Description copied from interface: SymbolTable
      Returns all overloads of the function with the given name in the specified namespace.
      Specified by:
      lookupFunction in interface SymbolTable
      Parameters:
      namespace - the target namespace (case-insensitive)
      name - the function name (case-insensitive)
      Returns:
      all matching function symbols; never null, may be empty
    • lookupFunction

      public Optional<FunctionSymbol> lookupFunction(String name, List<ScalarType> paramTypes)
      Description copied from interface: SymbolTable
      Returns the unique overload of the function named name whose parameter signature exactly matches paramTypes, searching "default" then "builtin".
      Specified by:
      lookupFunction in interface SymbolTable
      Parameters:
      name - the function name (case-insensitive)
      paramTypes - the ordered list of argument types to match
      Returns:
      the matching overload, or empty if no exact match exists
    • allSymbols

      public Collection<Symbol> allSymbols()
      Description copied from interface: SymbolTable
      Returns a snapshot of all symbols currently registered in the table, in registration order.
      Specified by:
      allSymbols in interface SymbolTable
      Returns:
      an unmodifiable collection of all symbols; never null