TreeNode<K> putTreeVal(int h, K k) {
      Class<?> kc = null;
      boolean searched = false;
      for (TreeNode<K> p = root;;) {
        int dir, ph;
        K pk;
        if (p == null) {
          first = root = new TreeNode<>(h, k, null, null);
          break;
        } else if ((ph = p.hash) > h) {
          dir = -1;
        } else if (ph < h) {
          dir = 1;
        } else if ((pk = p.key) == k || (pk != null && k.equals(pk))) {
          return p;
        } else if ((kc == null && (kc = comparableClassFor(k)) == null)
            || (dir = compareComparables(kc, k, pk)) == 0) {
          if (!searched) {
            TreeNode<K> q, ch;
            searched = true;
            if (((ch = p.left) != null && (q = ch.findTreeNode(h, k, kc)) != null)
                || ((ch = p.right) != null && (q = ch.findTreeNode(h, k, kc)) != null)) {
              return q;
            }
          }
          dir = tieBreakOrder(k, pk);
        }

        TreeNode<K> xp = p;
        if ((p = (dir <= 0) ? p.left : p.right) == null) {
          TreeNode<K> x, f = first;
          first = x = new TreeNode<>(h, k, f, xp);
          if (f != null) {
            f.prev = x;
          }
          if (dir <= 0) {
            xp.left = x;
          } else {
            xp.right = x;
          }
          if (!xp.red) {
            x.red = true;
          } else {
            lockRoot();
            try {
              root = balanceInsertion(root, x);
            } finally {
              unlockRoot();
            }
          }
          break;
        }
      }
      assert checkInvariants(root);
      return null;
    }
Finds or adds a node.

@return null if added
geode-core/src/main/java/org/apache/geode/internal/concurrent/CompactConcurrentHashSet2.java