private void DeleteKey(DataKey key)
{
if (key.position == this.position2)
{
if (key.prev != -1)
{
this.position2 = key.prev;
}
else
{
this.position1 = -1;
this.position2 = -1;
}
}
this.file.DeleteKey(key, false, true);
if (key.prev != -1)
{
var k = this.cache[key.number - 1];
if (k != null)
{
k.next = key.next;
if (!k.changed)
SetNext(key.prev, key.next);
}
else
{
SetNext(key.prev, key.next);
}
}
if (key.next != -1)
{
var k = this.cache[key.number + 1];
if (k != null)
{
k.prev = key.prev;
if (!k.changed)
SetPrev(key.next, key.prev);
}
else
{
SetPrev(key.next, key.prev);
}
}
for (int i = key.number; i < this.bufferCount - 1; i++)
{
this.cache[i] = this.cache[i + 1];
if (this.cache[i] != null)
this.cache[i].number = i;
}
this.bufferCount--;
this.file.WriteKey(this.key);
}