/* Copyright 2008 The 'A Concurrent Hashtable' development team (http://www.codeplex.com/CH/People/ProjectPeople.aspx) This library is licensed under the GNU Library General Public License (LGPL). You should have received a copy of the license along with the source code. If not, an online copy of the license can be found at http://www.codeplex.com/CH/license. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Orvid.Concurrent.Collections { internal class Segmentrange { protected Segmentrange() {} public static Segmentrange Create(int segmentCount, int initialSegmentSize) { var instance = new Segmentrange(); instance.Initialize(segmentCount, initialSegmentSize); return instance; } protected virtual void Initialize(int segmentCount, int initialSegmentSize) { _Segments = new Segment[segmentCount]; for (int i = 0, end = _Segments.Length; i != end; ++i) _Segments[i] = CreateSegment(initialSegmentSize); for (int w = segmentCount; w != 0; w <<= 1) ++_Shift; } protected virtual Segment CreateSegment(int initialSegmentSize) { return Segment.Create(initialSegmentSize); } Segment[] _Segments; Int32 _Shift; public Segment GetSegment(UInt32 hash) { return _Segments[hash >> _Shift]; } public Segment GetSegmentByIndex(Int32 index) { return _Segments[index]; } public Int32 Count { get { return _Segments.Length; } } public Int32 Shift { get { return _Shift; } } } }