コード例 #1
0
        internal void Remove(ref T data, ref BlockInfo blockInfo)
        {
            var block = new Block <T>(_bFactor, _emptyClass);
            // aktualizovat blockInfo ak sa vyprazdnil blok na ktory ukazuje
            var address = blockInfo.OverflowAddress;
            OverflowBlockInfo beforeInfo = null;

            var canContinue = true;

            while (canContinue)
            {
                ReadBlock(address, ref block);
                var info = _blocksInfoTable[address].Value;

                if (block.DeleteRecord(data) == null)
                {
                    if (info.NextOwerflowAddress != int.MinValue)
                    {
                        beforeInfo = info;
                        address    = info.NextOwerflowAddress;
                    }
                    else
                    {
                        // zaznam nebol najdeny
                        canContinue = false;
                    }
                }
                else
                {
                    --info.Records;
                    if (info.Records == 0)
                    {
                        // blok ostal prazdny tak prenastavime povodnemu bloku novu adresu zretazenia
                        // odstranime už nepotrebnu informaciu
                        // uvolnime adresu
                        if (beforeInfo != null)
                        {
                            beforeInfo.NextOwerflowAddress = info.NextOwerflowAddress;
                        }
                        else
                        {
                            blockInfo.OverflowAddress = info.NextOwerflowAddress;
                        }
                        _blocksInfoTable.Remove(address);
                        FreeAddress(address);
                    }
                    else
                    {
                        if (!TryShake(blockInfo.OverflowAddress, address, ref block, out var newOverflowAddress))
                        {
                            WriteBytes(address, block.ToByteArray());
                        }
                        else
                        {
                            if (newOverflowAddress >= 0)
                            {
                                blockInfo.OverflowAddress = newOverflowAddress;
                            }
                        }
                    }
                    canContinue = false;
                }
            }
        }