A C# queue package designed for high performance and ease of use

New: Dynamically evaluate C# expressions and execute C# scripts with a single statement, from anywhere in a .NET application. Click here for more info.

I’ve recently published a carefully constructed set of generic queues as part of the SharpByte project. These were all developed pursuant to the SharpByte CMS (the first of its type–more about which will be forthcoming), but are publicly released under the MIT license for any who wish to use them.

The priority queue abstract data type is similar to a regular queue, but allows each item to have a priority associated with it. For certain types of server-side programming this can be extremely useful for controlling the flow of work items. Implementations in the package include PriorityQueue and ConcurrentPriorityQueue.

The double-ended queue can be just as useful in its own way, as it can function as a queue, list (if list semantics are supported, as they are with this implementation), or stack. As such it’s one of the most useful general-purpose data structures. Implementations in the package include DoubleEndedQueue and ConcurrentDoubleEndedQueue.

Each queue in the package supports full list operations, and in fact implements IList and IList<T>. Performance has been tested and throughput on the queues under load was seen to be fast under a range of different processing conditions, including multithreading.

All queues in the package can also serve as connectors or work routers within an application, as they can have one or more outputs added, which can be any .NET collection capable of receiving items of the generic type supported by a particular queue. The semantics for this can be seen in the IQueue interface. Strategies for distribution to child queues/collections include multicasting, simple load-balancing, and round-robin distribution.

Also in the same collections package are potentially helpful odds and ends, including read-only dictionary and list collections, as well as read-only views of mutable dictionaries and lists. These are different from the read-only interfaces now supported in .NET, as they cannot be cast successfully to mutable dictionaries and lists. The CharHashSet class is an implementation of ISet for chars which generally outperforms HashSet<char>, and can be useful for certain specialized operations dealing with strings.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s