@CanIgnoreReturnValue
  @VisibleForTesting
  DirectoryEntry remove(Name name) {
    int index = bucketIndex(name, table.length);

    DirectoryEntry prev = null;
    DirectoryEntry entry = table[index];
    while (entry != null) {
      if (name.equals(entry.name())) {
        if (prev != null) {
          prev.next = entry.next;
        } else {
          table[index] = entry.next;
        }

        entry.next = null;
        entryCount--;
        entry.file().decrementLinkCount();
        return entry;
      }

      prev = entry;
      entry = entry.next;
    }

    throw new IllegalArgumentException("no entry matching '" + name + "' in this directory");
  }
@Test
  public void testRemove() {
    dir.put(entry("foo"));
    dir.put(entry("bar"));

    dir.remove(Name.simple("foo"));

    assertThat(dir.entryCount()).isEqualTo(3);
    assertThat(ImmutableSet.copyOf(dir))
        .containsExactly(
            entry("bar"),
            new DirectoryEntry(dir, Name.SELF, dir),
            new DirectoryEntry(dir, Name.PARENT, root));
    assertThat(dir.get(Name.simple("foo"))).isNull();
    assertThat(dir.get(Name.simple("bar"))).isEqualTo(entry("bar"));

    dir.remove(Name.simple("bar"));

    assertThat(dir.entryCount()).isEqualTo(2);

    dir.put(entry("bar"));
    dir.put(entry("foo")); // these should just succeeded
  }