Click here to Skip to main content
15,895,370 members
Articles / Programming Languages / C#

A Concurrent Collection: a MultiMap Generic Collection Class in C# - Part 2

Rate me:
Please Sign up or sign in to vote.
4.87/5 (19 votes)
5 Jun 2009CPOL10 min read 102.8K   3.4K   73  
MultiMap is similar to a .NET Dictionary collection type, but accepts duplicate Key,Value pairs during addition. The MultiMap collection is also a concurrent collection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BK.Util
{
    /// <summary>
    /// Contains Key and Value(s). i.e., Value.First, Value.Next and so on
    /// </summary>
    /// <typeparam name="Key"></typeparam>
    /// <typeparam name="Value"></typeparam>
    public class ValueItem<Key, Value> where Key: IComparable<Key>
    {
        private MultimapBK<Key, Value> multiMap;
        private Key key;


        internal ValueItem(MultimapBK<Key, Value> multiMapItem, Key KeyItem)
        {
            key = KeyItem;
            multiMap = multiMapItem;
        }

        
        /// <summary>
        /// Returns the first Item
        /// </summary>
        public Value First
        {
            get
            {
                return multiMap.GetFirstItem(key);
            }
        }
        /// <summary>
        /// Move to Next Item
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            return multiMap.MoveToNextItem(key);
        }

        /// <summary>
        /// Return Current Item
        /// </summary>
        public Value Current
        {
            get
            {
                return multiMap.GetCurrentItem(key);
            }
        }

        /// <summary>
        /// Reset to first Item. 
        /// </summary>
        public void Reset()
        {
            multiMap.ResetToFirstItem(key);
        }

        /// <summary>
        /// Returns the Next Item
        /// </summary>
        public Value Next
        {
            get
            {
                return multiMap.GetNextItem(key);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions