tejacques / deque Goto Github PK
View Code? Open in Web Editor NEWA C# Deque class
License: MIT License
A C# Deque class
License: MIT License
If you add elements using InsertRange
, some elements might be cloned and other elements disappear.
For example:
var deque = new Deque<string>(new string[] { "angel", "clown", "mandarin", "surgeon" });
deque.InsertRange(2, new string[] { "drum" });
At this point you expect deque
to contain ["angel", "clown", "drum", "mandarin", "surgeon"]
, but it actually contains ["angel", "clown", "drum", "mandarin", "mandarin"]
. "mandarin"
got duplicated but "surgeon"
got removed.
This involves two parts
version
which increases on any mutating operation.GetEnumerator()
call which throws when the version
has changed.This may or may not be more performant, and remains to be tested, but will be more correct.
Because it doesn't do this, it causes references to those objects to be held until they are overwritten in the Deque or the Deque is collected by the GC.
Should be toBufferIndex(this.Count)
and toBufferIndex(length)
This test fails.
[Test]
public void TestAddBack()
{
Deque<int> deque = new Deque<int>();
deque.AddBack(1);
deque.RemoveFront();
deque.AddBack(1);
Assert.AreEqual(1, deque.RemoveFront());
}
Change AddBack()
to use this
buffer[toBufferIndex(this.Count)] = item;
instead of
buffer[toBufferIndex(this.startOffset + this.Count)] = item;
to fix it. And thanks, this class is useful.
Deque is a very useful class, but unfortunately I can't reference it in my Windows Phone and Xamarin projects.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.