getParentKey method

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

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;
}