Package dev.cel.common.ast
Class CelExprIdGeneratorFactory.StableIdGenerator
- java.lang.Object
-
- dev.cel.common.ast.CelExprIdGeneratorFactory.StableIdGenerator
-
- Enclosing class:
- CelExprIdGeneratorFactory
public static class CelExprIdGeneratorFactory.StableIdGenerator extends java.lang.ObjectStableIdGenerator 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 booleanhasId(long id)Checks if the given ID has been encountered before.voidmemoize(long existingId, long newId)Memoize a given expression ID with a newly generated ID.longnextExprId()Generates the next available ID.longnextExprId(long id)Generate the next available ID while memoizing the existing ID.longrenumberId(long id)Renumbers the existing expression ID to a newly generated unique ID.
-
-
-
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 aCelExprIdGeneratorFactory.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.
-
-