~kelemeng/banshee/bug743928

« back to all changes in this revision

Viewing changes to src/Hyena/Hyena/Hyena.Collections/RangeCollection.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2011-05-14 22:25:36 UTC
  • mfrom: (6.3.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20110514222536-u1x7ikxdqkmfvyuz
Tags: 2.1.0-1ubuntu1
* [2396c18] Merge from Debian Unstable, remaining changes:
  + Enable SoundMenu and Disable NotificationArea by default
  + Disable boo and karma extensions
  + Enable and recommnd u1ms and soundmenu extensions
  + Move desktop file for Meego UI to /usr/share/une/applications
  + Change the url for the Amazon store redirector
  + Create the U1MS widget earlier and bump libu1 requirement
* [9d7c600] Drop upstreamed u1ms-initialize-earlier patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using System;
30
30
using System.Collections;
31
 
 
32
 
#if NET_2_0
33
31
using System.Collections.Generic;
34
 
#endif
35
32
 
36
 
#if NET_1_1
37
 
namespace System.Collections
38
 
#else
39
33
namespace Hyena.Collections
40
 
#endif
41
34
{
42
 
#if NET_1_1
43
 
    internal
44
 
#else
45
35
    public
46
 
#endif
47
36
 
48
 
    class RangeCollection :
49
 
        ICloneable,
50
 
#if NET_2_0
51
 
        ICollection<int>
52
 
#else
53
 
        ICollection
54
 
#endif
 
37
    class RangeCollection : ICloneable, ICollection<int>
55
38
    {
56
39
        public struct Range
57
40
        {
88
71
        private Range [] ranges;
89
72
        private int range_count;
90
73
        private int index_count;
91
 
        private int generation;
92
 
        private int [] indexes_cache;
93
 
        private int indexes_cache_generation;
94
74
 
95
75
        public RangeCollection ()
96
76
        {
121
101
                new_capacity <<= 1;
122
102
            }
123
103
 
124
 
#if NET_2_0
125
104
            Array.Resize (ref ranges, new_capacity);
126
 
#else
127
 
            Range [] new_ranges = new Range[new_capacity];
128
 
            Array.Copy (ranges, 0, new_ranges, 0, ranges.Length);
129
 
            ranges = new_ranges;
130
 
#endif
131
105
        }
132
106
 
133
107
        private void Insert (int position, Range range)
275
249
            get { return range_count; }
276
250
        }
277
251
 
278
 
#if NET_2_0
279
 
        [Obsolete ("Do not use the Indexes property in 2.0 profiles if enumerating only; Indexes allocates an array to avoid boxing in the 1.1 profile")]
280
 
#endif
281
 
        public int [] Indexes {
282
 
            get {
283
 
                if (indexes_cache != null && generation == indexes_cache_generation) {
284
 
                    return indexes_cache;
285
 
                }
286
 
 
287
 
                indexes_cache = new int[Count];
288
 
                indexes_cache_generation = generation;
289
 
 
290
 
                for (int i = 0, j = 0; i < range_count; i++) {
291
 
                    for (int k = ranges[i].Start; k <= ranges[i].End; j++, k++) {
292
 
                        indexes_cache[j] = k;
293
 
                    }
294
 
                }
295
 
 
296
 
                return indexes_cache;
297
 
            }
298
 
        }
299
 
 
300
252
        public int IndexOf (int value)
301
253
        {
302
254
            int offset = 0;
331
283
        public bool Add (int value)
332
284
        {
333
285
            if (!Contains (value)) {
334
 
                generation++;
335
286
                InsertRange (new Range (value, value));
336
287
                index_count++;
337
288
                return true;
340
291
            return false;
341
292
        }
342
293
 
343
 
        void
344
 
#if NET_2_0
345
 
        ICollection<int>.
346
 
#else
347
 
        ICollection.
348
 
#endif
349
 
        Add (int value)
 
294
        void ICollection<int>.Add (int value)
350
295
        {
351
296
            Add (value);
352
297
        }
353
298
 
354
299
        public bool Remove (int value)
355
300
        {
356
 
            generation++;
357
301
            return RemoveIndexFromRange (value);
358
302
        }
359
303
 
361
305
        {
362
306
            range_count = 0;
363
307
            index_count = 0;
364
 
            generation++;
365
308
            ranges = new Range[MIN_CAPACITY];
366
309
        }
367
310
 
388
331
            get { return false; }
389
332
        }
390
333
 
391
 
#if !NET_2_0
392
 
        public bool IsSynchronized {
393
 
            get { return false; }
394
 
        }
395
 
 
396
 
        public object SyncRoot {
397
 
            get { return this; }
398
 
        }
399
 
#endif
400
 
 
401
334
#endregion
402
335
 
403
336
#region ICloneable Implementation
411
344
 
412
345
#region IEnumerable Implementation
413
346
 
414
 
#if NET_2_0
415
347
        public IEnumerator<int> GetEnumerator ()
416
348
        {
417
349
            for (int i = 0; i < range_count; i++) {
425
357
        {
426
358
            return GetEnumerator ();
427
359
        }
428
 
#else
429
 
        public IEnumerator GetEnumerator ()
430
 
        {
431
 
            return Indexes.GetEnumerator ();
432
 
        }
433
 
#endif
434
360
 
435
361
#endregion
436
362