public static int treeHash(Node node, Function<Node, OptionalInt> subtreeHasher) {
    OptionalInt hash = subtreeHasher.apply(node);

    if (hash.isPresent()) {
      return hash.getAsInt();
    }

    List<? extends Node> children = node.getChildren();

    int result = node.getClass().hashCode();
    for (Node element : children) {
      result = 31 * result + treeHash(element, subtreeHasher);
    }

    return result;
  }
Computes a hash of the given AST by applying the provided subtree hasher at each level.

<p>If the hasher returns a non-empty {@link OptionalInt}, the value is treated as the hash for
the subtree at that node. Otherwise, the hashes of its children are computed and combined.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/util/AstUtil.java