docs: @Requires({
      "isValidPattern(pattern)",
      "rule != null"
    })
    @Ensures({
      "rule.equals(get(pattern))",
      "!isOverriden(pattern)"
    })
    public void put(String pattern, R rule) {
      String canon = pattern.replace('/', '.');
      boolean exact = !canon.endsWith(".*");
      if (!exact) {
        canon = canon.substring(0, canon.length() - 2);
      }
  
      String[] parts = canon.split("\\.");
  
      TernaryNode current = root;
      TernaryNode parent = root;
      int parentIndex = -1;
      for (int i = 0; i < parts.length; ++i) {
        TernaryNode next = current.children.get(parts[i]);
        if (next == null) {
          next = new TernaryNode(null, false);
          current.children.put(parts[i], next);
        }
        if (next.rule != null && !next.exact) {
          parent = next;
          parentIndex = i;
        }
        current = next;
      }
  
      if (!exact) {
        /* Override patterns beginning with this one. */
        current.children.clear();
      }
  
      if (!rule.equals(parent.rule)) {
        current.rule = rule;
        current.exact = exact;
      } else {
        /*
         * The new rule we are inserting is already specified through
         * inheritance. Remove spurious nodes. This ensures that any
         * overriding branch is meaningful; that is, it specifies a rule
         * value different from the inherited one.
         */
        current = parent;
        for (int i = parentIndex + 1; i < parts.length; ++i) {
          TernaryNode next = current.children.get(parts[i]);
          if (next.rule == null) {
            current.children.remove(parts[i]);
            break;
          }
        }
      }
    }