lastBlockCount is called lastBlockEndIndex again (anyone got a better term - it's an index one past the last entry, not a count); implemented the CopyTo() method; added unit tests for the CopyTo() method

git-svn-id: file:///srv/devel/repo-conversion/nusu@164 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2009-07-14 21:08:10 +00:00
parent 3ee5fdfc67
commit 0b23b1f7c4
6 changed files with 120 additions and 31 deletions

View file

@ -23,14 +23,14 @@ namespace Nuclex.Support.Collections {
/// <summary>Appends an item to the end of the double-ended queue</summary>
/// <param name="item">Item that will be appended to the queue</param>
public void AddLast(ItemType item) {
if(this.lastBlockCount < this.blockSize) {
++this.lastBlockCount;
if(this.lastBlockEndIndex < this.blockSize) {
++this.lastBlockEndIndex;
} else { // Need to allocate a new block
this.blocks.Add(new ItemType[this.blockSize]);
this.lastBlockCount = 1;
this.lastBlockEndIndex = 1;
}
this.blocks[this.blocks.Count - 1][this.lastBlockCount - 1] = item;
this.blocks[this.blocks.Count - 1][this.lastBlockEndIndex - 1] = item;
++this.count;
}
@ -137,15 +137,15 @@ namespace Nuclex.Support.Collections {
int blockLength;
// If the lastmost block is full, we need to add another block
if(this.lastBlockCount == this.blockSize) {
if(this.lastBlockEndIndex == this.blockSize) {
this.blocks.Add(new ItemType[this.blockSize]);
this.blocks[lastBlock + 1][0] = this.blocks[lastBlock][this.blockSize - 1];
this.lastBlockCount = 1;
this.lastBlockEndIndex = 1;
blockLength = this.blockSize - 1;
} else {
blockLength = this.lastBlockCount;
++this.lastBlockCount;
blockLength = this.lastBlockEndIndex;
++this.lastBlockEndIndex;
}
// If the insertion point is not in the lastmost block