public void FreeAddress(int address) { // ak to bolo adresa na konci tak zmazať všetky volne adresy od konca až po platne data if (address == LastAddress - _blockSize) // LastAddress - _blockSize -> posledna pridelena adresa.. na LastAddress ešte nič nie je { var blocksToErase = 1; for (int i = _freeAddresses.Count - 1; i >= 0; i--) { var key = _freeAddresses.Items[i].Key; if (key == address - _blockSize) { address = key; ++blocksToErase; } else { break; } } _fileStream.Seek(0, SeekOrigin.Begin); _fileStream.SetLength(LastAddress - blocksToErase * _blockSize); if (blocksToErase > 1) // lebo ak je 1, tak sa tam ani nedostala { --blocksToErase; _freeAddresses.RemoveRange(_freeAddresses.Count - blocksToErase, blocksToErase); } } else { _freeAddresses.Add(address, address); } }
public void Find_ReturnsIndexesWithExpectedOrdering() { SortedTable <int> table = new SortedTable <int>(); table.Add(1); table.Add(2); table.Add(3); SortedTable <int> .Index index1 = table.Find(1); SortedTable <int> .Index index2 = table.Find(2); SortedTable <int> .Index index3 = table.Find(3); Assert.True(index1.CompareTo(index1) == 0); Assert.True(index1.Equals(index1)); Assert.False(index1.Equals(index2)); Assert.True(index1.CompareTo(index2) < 0); Assert.True(index1.CompareTo(index3) < 0); Assert.True(index2.CompareTo(index1) > 0); Assert.True(index2.CompareTo(index2) == 0); Assert.True(index2.Equals(index2)); Assert.False(index2.Equals(index3)); Assert.True(index2.CompareTo(index3) < 0); Assert.True(index3.CompareTo(index1) > 0); Assert.True(index3.CompareTo(index2) > 0); Assert.True(index3.CompareTo(index3) == 0); Assert.True(index3.Equals(index3)); Assert.False(index3.Equals(index1)); }
/// <summary> /// Adds a new block at he end of the existing sequence of overflow blocks /// </summary> /// <param name="data"></param> /// <param name="block"></param> /// <param name="blockInfo"></param> private void AddNewOverflowBlock(ref T data, ref Block <T> block, ref OverflowBlockInfo blockInfo) { var address = GetFreeAddress(); block.ValidCount = 0; block.AddRecord(data); WriteBytes(address, block.ToByteArray()); blockInfo.NextOwerflowAddress = address; _blocksInfoTable.Add(address, new OverflowBlockInfo()); }
public void Find_NotEmptyButNotPresent_ReturnsInvalidIndex() { SortedTable <int> table = new SortedTable <int>(); table.Add(1); table.Add(2); SortedTable <int> .Index index = table.Find(3); Assert.False(index.IsValid); }
public void Add_UpdatesCount() { SortedTable <int> table = new SortedTable <int>(); Assert.Equal(0, table.Count); table.Add(1); Assert.Equal(1, table.Count); table.Add(2); Assert.Equal(2, table.Count); }
public void Find_NotEmptyAndPresent_ReturnsValidIndex() { SortedTable <int> table = new SortedTable <int>(); table.Add(1); table.Add(2); table.Add(3); SortedTable <int> .Index index = table.Find(3); Assert.True(index.IsValid); index = table.Find(1); Assert.True(index.IsValid); }
public void Add_ReturnsTrueIfAddedFalseIfAlreadyPresent() { SortedTable <int> table = new SortedTable <int>(); Assert.True(table.Add(1)); Assert.Equal(1, table.Count); Assert.False(table.Add(1)); Assert.Equal(1, table.Count); Assert.True(table.Add(2)); Assert.Equal(2, table.Count); Assert.False(table.Add(2)); Assert.Equal(2, table.Count); }
public void Crunch_ColumnsLessThanRows_ReturnsColumnIndexesFirst() { Word2Grid grid = new Word2Grid(new Word2("zb"), new Word2("ae")); SortedTable <Word2> table = new SortedTable <Word2>(); table.Add(new Word2("ae")); table.Add(new Word2("be")); table.Add(new Word2("za")); table.Add(new Word2("zb")); Word2GridCruncher cruncher = new Word2GridCruncher(table); CrunchedWord2Grid crunchedGrid = cruncher.Crunch(grid); CrunchedWord2Grid expectedGrid = new CrunchedWord2Grid(Idx(3), Idx(2), Idx(4), Idx(1)); Assert.Equal(expectedGrid, crunchedGrid); }
private int Add(string NameC, int Code) { int i = MainTable.Count; MainTable.Add(new SymbolTableItem(NameC, Code)); SortedTable.Add(NameC, i); return(i); }
public void Crunch_FirstColumnAndRowEqualButSecondColumnGreater_ReturnsRowIndexesFirst() { Word3Grid grid = new Word3Grid(new Word3("abc"), new Word3("baa"), new Word3("cza")); SortedTable <Word3> table = new SortedTable <Word3>(); table.Add(new Word3("abc")); table.Add(new Word3("baa")); table.Add(new Word3("baz")); table.Add(new Word3("caa")); table.Add(new Word3("cza")); Word3GridCruncher cruncher = new Word3GridCruncher(table); CrunchedWord3Grid crunchedGrid = cruncher.Crunch(grid); CrunchedWord3Grid expectedGrid = new CrunchedWord3Grid(Idx(1), Idx(2), Idx(5), Idx(1), Idx(3), Idx(4)); Assert.Equal(expectedGrid, crunchedGrid); }
public void Enumerator_YieldsInOrder() { SortedTable <int> table = new SortedTable <int>(); table.Add(4); table.Add(2); table.Add(3); table.Add(1); List <int> items = new List <int>(); foreach (int item in table) { items.Add(item); } Assert.Equal(new int[] { 1, 2, 3, 4 }, items.ToArray()); }
public void Crunch_ColumnsLessThanRows_ReturnsColumnIndexesFirst() { Word4Grid grid = new Word4Grid(new Word4("zbcd"), new Word4("aefg"), new Word4("ahij"), new Word4("aklm")); SortedTable <Word4> table = new SortedTable <Word4>(); table.Add(new Word4("aefg")); table.Add(new Word4("ahij")); table.Add(new Word4("aklm")); table.Add(new Word4("behk")); table.Add(new Word4("cfil")); table.Add(new Word4("dgjm")); table.Add(new Word4("zaaa")); table.Add(new Word4("zbcd")); Word4GridCruncher cruncher = new Word4GridCruncher(table); CrunchedWord4Grid crunchedGrid = cruncher.Crunch(grid); CrunchedWord4Grid expectedGrid = new CrunchedWord4Grid(Idx(7), Idx(4), Idx(5), Idx(6), Idx(8), Idx(1), Idx(2), Idx(3)); Assert.Equal(expectedGrid, crunchedGrid); }
public void Crunch_FirstColumnAndRowEqualButSecondRowGreater_ReturnsColumnIndexesFirst() { Word4Grid grid = new Word4Grid(new Word4("abcd"), new Word4("bzzz"), new Word4("caaa"), new Word4("daaa")); SortedTable <Word4> table = new SortedTable <Word4>(); table.Add(new Word4("abcd")); table.Add(new Word4("bzaa")); table.Add(new Word4("bzzz")); table.Add(new Word4("caaa")); table.Add(new Word4("czaa")); table.Add(new Word4("daaa")); table.Add(new Word4("dzaa")); Word4GridCruncher cruncher = new Word4GridCruncher(table); CrunchedWord4Grid crunchedGrid = cruncher.Crunch(grid); CrunchedWord4Grid expectedGrid = new CrunchedWord4Grid(Idx(1), Idx(2), Idx(5), Idx(7), Idx(1), Idx(3), Idx(4), Idx(6)); Assert.Equal(expectedGrid, crunchedGrid); }
public void Crunch_ColumnsLessThanRows_ReturnsColumnIndexesFirst() { Word3Grid grid = new Word3Grid(new Word3("zbc"), new Word3("aef"), new Word3("ahi")); SortedTable <Word3> table = new SortedTable <Word3>(); table.Add(new Word3("aef")); table.Add(new Word3("ahi")); table.Add(new Word3("beh")); table.Add(new Word3("cfi")); table.Add(new Word3("zaa")); table.Add(new Word3("zbc")); Word3GridCruncher cruncher = new Word3GridCruncher(table); CrunchedWord3Grid crunchedGrid = cruncher.Crunch(grid); CrunchedWord3Grid expectedGrid = new CrunchedWord3Grid(Idx(5), Idx(3), Idx(4), Idx(6), Idx(1), Idx(2)); Assert.Equal(expectedGrid, crunchedGrid); }
public void Crunch_FirstAndSecondColumnAndRowEqualButThirdColumnGreater_ReturnsRowIndexesFirst() { Word4Grid grid = new Word4Grid(new Word4("abcd"), new Word4("bcde"), new Word4("cdza"), new Word4("deza")); SortedTable <Word4> table = new SortedTable <Word4>(); table.Add(new Word4("abcd")); table.Add(new Word4("bcde")); table.Add(new Word4("cdza")); table.Add(new Word4("cdzz")); table.Add(new Word4("deaa")); table.Add(new Word4("deza")); Word4GridCruncher cruncher = new Word4GridCruncher(table); CrunchedWord4Grid crunchedGrid = cruncher.Crunch(grid); CrunchedWord4Grid expectedGrid = new CrunchedWord4Grid(Idx(1), Idx(2), Idx(3), Idx(6), Idx(1), Idx(2), Idx(4), Idx(5)); Assert.Equal(expectedGrid, crunchedGrid); }