Class CelExprIdGeneratorFactory.StableIdGenerator

  • Enclosing class:
    CelExprIdGeneratorFactory

    public static class CelExprIdGeneratorFactory.StableIdGenerator
    extends java.lang.Object
    StableIdGenerator ensures new IDs are only created the first time they are encountered.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasId​(long id)
      Checks if the given ID has been encountered before.
      void memoize​(long existingId, long newId)
      Memoize a given expression ID with a newly generated ID.
      long nextExprId()
      Generates the next available ID.
      long nextExprId​(long id)
      Generate the next available ID while memoizing the existing ID.
      long renumberId​(long id)
      Renumbers the existing expression ID to a newly generated unique ID.
      • Methods inherited from class java.lang.Object

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

      • hasId

        public boolean hasId​(long id)
        Checks if the given ID has been encountered before.
      • nextExprId

        public long nextExprId()
        Generates the next available ID.
      • nextExprId

        public long nextExprId​(long id)
        Generate the next available ID while memoizing the existing ID.

        The main purpose of this is to sanitize a new AST to replace an existing AST's node with. The incoming AST may not have its IDs consistently numbered (often, the expr IDs are just zeroes). In those cases, we just want to return an incremented expr ID.

        The memoization becomes necessary if the incoming AST contains an expression with macro map populated, requiring a normalization pass. In this case, the method behaves largely the same as renumberId(long).

        Parameters:
        id - Existing ID to memoize. Providing 0 or less will skip the memoization, in which case this behaves just like a CelExprIdGeneratorFactory.MonotonicIdGenerator.
      • memoize

        public void memoize​(long existingId,
                            long newId)
        Memoize a given expression ID with a newly generated ID.
      • renumberId

        public long renumberId​(long id)
        Renumbers the existing expression ID to a newly generated unique ID. The existing ID is memoized, and calling this method again with the same ID will always return the same generated ID.