getParentKey method

Node? getParentKey(
  1. Node? child, {
  2. bool includePurgedEntries = false,
})
inherited

Get 1st parent key of child;

Implementation

K? getParentKey(K? child, {bool includePurgedEntries = false}) {
  if (child == null || identical(child, root)) return null;

  if (includePurgedEntries) {
    var purged = _purged ?? <K, MapEntry<DateTime, V>>{};
    var cursor = getParentOf(child);
    while (cursor != null) {
      if (_map.containsKey(cursor) || purged.containsKey(cursor)) {
        return cursor;
      }
      cursor = getParentOf(cursor);
    }
  } else {
    var cursor = getParentOf(child);
    while (cursor != null) {
      if (_map.containsKey(cursor)) return cursor;
      cursor = getParentOf(cursor);
    }
  }

  if (isChildOf(root, child, false)) {
    return root;
  }

  return null;
}