Last active
September 11, 2016 21:37
-
-
Save erinxocon/1f975d74064c1afdb2d8cf39521fc729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FixedSizedLinkedList<T> : LinkedList<T> | |
{ | |
private readonly object syncObject = new object(); | |
public int Size { get; private set; } | |
public FixedSizedLinkedList(int size) | |
{ | |
Size = size; | |
} | |
public new void AddFirst(T obj) | |
{ | |
base.AddFirst(obj); | |
lock (syncObject) | |
{ | |
while (base.Count > Size) | |
{ | |
base.RemoveLast(); | |
} | |
} | |
} | |
public new void AddLast (T obj) | |
{ | |
base.AddLast(obj); | |
lock (syncObject) | |
{ | |
while (base.Count > Size) | |
{ | |
base.RemoveFirst(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment