Channels ▼
RSS

.NET

The C5 Generic Collection Library

Source Code Accompanies This Article. Download It Now.


Implementation Challenges

Some of the functionality in C5 is difficult to implement efficiently—the combination of hash indexes and sublist views on linked lists, for instance.

First, it is fairly easy to provide each of these two extensions in isolation. A hash-indexed linked list in C5 is implemented by maintaining a hash dictionary that maps an item x to the list node in which it appears (if any). A sublist view is implemented as a pair of the list node just before the view and the list node just after the view, and all proper lists have an artificial sentinel node added before and after the list.

However, combining the two features is nontrivial because hash-based item lookup should work on sublist views too, and we want to share a single hash dictionary between all views of a list (or else view sliding would be extremely slow). So when performing hash-based item lookup on a view, we need to quickly decide whether the resulting item falls within the given view, not somewhere else in the underlying list. Traversing the view to see whether the item is within the view would be slow and would defeat the purpose of the hash index.

Instead, we adopt a list-ordering algorithm due to Sleator and Dietz in the version described by Bender (theory.lcs.mit.edu/ ~edemaine/papers/DietzSleator_ESA2002/ paper.pdf). The basic idea is to give each list node an integer tag so that nodes appear in a strictly increasing tag order. The Sleator-Dietz-Bender algorithm describes how to efficiently redistribute node tags at insertions so that a newly inserted node can be given a tag strictly between those of its neighbors. In the C5 implementation, we use a two-level version of this basic scheme, by maintaining tags on groups of nodes at the first level, and tagging the groups themselves at the second level.

Conclusion

Informal feedback from users has been very positive, showing that the C5 library provides useful, advanced and well-tested collection classes.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video