Buckets

We found 10 examples in language CSharp for this search. You will see 39 fragments of code.

Other methods


        private Bucket[] Order(Bucket[] buckets)
        {
            if (!IsOrdered(buckets))
            {
                buckets = buckets.OrderBy(b => b.MinKey).ToArray();
            }

            return buckets;
        }

        private bool IsOrdered(Bucket[] buckets)
        {
            for (int i = 1, n = buckets.Length; i < n; i++)
            {
                if (comparer.Compare(buckets[i].MinKey, buckets[i - 1].MinKey) < 0)
                {
                    return false;
                }
            }

            return true;
        }

        private int GetBucket(Bucket[] buckets, K key)
        {
            Debug.Assert(buckets != null);
            return buckets.BinarySearch(key, (k, bucket) => comparer.Compare(k, bucket.MinKey));
        }

        private Bucket ReplaceAt(Bucket bucket, Bucket newBucket, int index)
        {
            if (bucket.Buckets[index] != newBucket)
            {
                Bucket[] newBuckets = new Bucket[bucket.Buckets.Length];
                Array.Copy(bucket.Buckets, newBuckets, newBuckets.Length);
                newBuckets[index] = newBucket;
                return new Bucket(newBuckets);
            }

            return bucket;
        }


        public IEnumerator<object> GetEnumerator() {
            if (_hasNull) {
                yield return null;
            }

            if (_count == 0) {
                yield break;
            }

            Bucket[] buckets = _buckets;
            for (int i = 0; i < buckets.Length; i++) {
                object item = buckets[i].Item;
                if (item != null && item != Removed) {
                    yield return item;
                }
            }
        }

        private static void ProbeNext(Bucket[]/*!*/ buckets, ref int index) {
            Debug.Assert(buckets != null);

            index++;
            if (index == buckets.Length) {
                index = 0;
            }
        }


        /// <summary>
        /// Add helper that works over a single set of buckets.  Used for
        /// both the normal add case as well as the resize case.
        /// </summary>
        private bool Add(Bucket[] buckets, object key, object value) {
            int hc = Hash(key);

            return AddWorker(buckets, key, value, hc);
        }

       private static int ProbeNext(Bucket[] buckets, int index) {
           // probe to next bucket               
           index++;
           if (index == buckets.Length) {
               index = 0;
           }
           return index;
       }


        public void AddSample(T sample)
        {
            MoveWindow();

            int curBucket = (int)(curBucketGlobal % NumBuckets);
            buckets[curBucket].value = Add(buckets[curBucket].value, sample);
            buckets[curBucket].count++;

            totalSum = Add(totalSum, sample);
            totalCount++;
        }

        /// <summary>
        /// Clears the values in buckets [offset, offset+num)
        /// </summary>
        private void ZeroBuckets(int offset, int num)
        {
            for (int i = 0; i < num; i++)
            {
                buckets[offset + i].value = GetZero();
                buckets[offset + i].count = 0;
            }
        }

        private void RecalcTotal()
        {
            totalSum = GetZero();
            totalCount = 0;

            for (int i = 0; i < NumBuckets; i++)
            {
                totalSum = Add(totalSum, buckets[i].value);
                totalCount += buckets[i].count;
            }
        }


			public void Clear()
			{
				if (_count == 0)
					return;

				int[] buckets = _buckets;
				for (int i = 0; i < buckets.Length; ++i)
					buckets[i] = -1;
				_count = 0;
			}

			private void Initialise(int capacity)
			{
				int n = 3;
				while (true)
				{
					int pow = 2 << n;
					if (pow >= capacity)
					{
						capacity = pow;
						break;
					}

					++n;
				}

				var buckets = new int[capacity << 1];
				for (int i = 0; i < buckets.Length; i++)
					buckets[i] = -1;
				_buckets = buckets;
				_size = capacity;
			}

			private int SearchIndex(GameTag t)
			{
				int k = (int)t;
				int h = (k & (_size - 1)) << 1;
				int[] buckets = _buckets;
				for (int i = h; i < _buckets.Length; i += 2)
				{
					if (buckets[i] == k)
						return i;
					if (buckets[i] < 0)
						return -1;
				}
				for (int i = 0; i < h; i += 2)
				{
					if (buckets[i] < 0)
						return -1;
					if (buckets[i] == k)
						return i;
				}

				return -1;
			}

			public IEnumerator<KeyValuePair<GameTag, int>> GetEnumerator()
			{
				int[] buckets = _buckets;
				for (int i = 0; i < buckets.Length; i += 2)
				{
					if (buckets[i] > 0)
						yield return new KeyValuePair<GameTag, int>((GameTag)_buckets[i], _buckets[i + 1]);
				}
			}


		public void Clear()
		{
			if (_count == 0)
				return;

			int[] buckets = _buckets;
			for (int i = 0; i < buckets.Length; ++i)
				buckets[i] = -1;
			_count = 0;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private void Initialise(int capacity)
		{
			int pow = 8;
			while (pow < capacity)
				pow *= 2;

			int[] buckets = new int[pow << 1];
			for (int i = 0; i < buckets.Length; i +=2)
				buckets[i] = -1;
			_buckets = buckets;

			_size = pow;
		}

		public IEnumerator<KeyValuePair<GameTag, int>> GetEnumerator()
		{
			int[] buckets = _buckets;
			for (int i = 0; i < buckets.Length; i += 2)
			{
				if (buckets[i] > 0)
					yield return new KeyValuePair<GameTag, int>((GameTag)buckets[i], buckets[i + 1]);
			}
		}


		public void Clear()
		{
			if (_count == 0)
				return;

			int[] buckets = _buckets;
			for (int i = 0; i < buckets.Length; ++i)
				buckets[i] = -1;
			_count = 0;
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private void Initialise(int capacity)
		{
			int pow = 8;
			while (pow < capacity)
				pow *= 2;

			int[] buckets = new int[pow << 1];
			for (int i = 0; i < buckets.Length; i +=2)
				buckets[i] = -1;
			_buckets = buckets;

			_size = pow;
		}

		public IEnumerator<KeyValuePair<GameTag, int>> GetEnumerator()
		{
			int[] buckets = _buckets;
			for (int i = 0; i < buckets.Length; i += 2)
			{
				if (buckets[i] > 0)
					yield return new KeyValuePair<GameTag, int>((GameTag)buckets[i], buckets[i + 1]);
			}
		}


        internal AnalysisHashSet AddFromEnumerator(IEnumerator<AnalysisValue> items) {
            var buckets = Buckets;
            AddFromEnumerator(ref buckets, items, Comparer);
            Buckets = buckets;
            return this;
        }

        private static bool AddFromEnumerator(ref BucketSet buckets, IEnumerator<AnalysisValue> items, IEqualityComparer<AnalysisValue> comparer) {
            bool wasChanged = false;
            while (items.MoveNext()) {
                wasChanged |= AddOne(ref buckets, items.Current, comparer);
            }
            return wasChanged;
        }

        private static bool AddOne(ref BucketSet buckets, AnalysisValue key, IEqualityComparer<AnalysisValue> comparer) {
            if (buckets.Buckets == null) {
                buckets = new BucketSet(InitialBucketSize);
            }

            int hc = comparer.GetHashCode(key) & Int32.MaxValue;
            if (AddOne(ref buckets, key, hc, comparer)) {
                CheckGrow(ref buckets, comparer);
                return true;
            }
            return false;
        }

        private static void CheckGrow(ref BucketSet buckets, IEqualityComparer<AnalysisValue> comparer) {
            if (buckets.Capacity == 0) {
                return;
            }
            if (buckets.Count >= (buckets.Capacity * Load)) {
                // grow the hash table
                EnsureSize(ref buckets, (int)(buckets.Capacity / Load) * ResizeMultiplier, comparer);
            }
        }

        private static int ProbeNext(Bucket[] buckets, int index) {
            // probe to next bucket    
            return (index + ((buckets.Length - 1) / 2)) % buckets.Length;
        }

        /// <summary>
        /// Checks to see if the key exists in the dictionary.
        /// </summary>
        public bool Contains(AnalysisValue key) {
            if (key == null) {
                throw new ArgumentNullException("key");
            }
            return Contains(Buckets.Buckets, key) >= 0;
        }


        protected override long Add(long a, long b) { return a + b; }

        public void AddSample(Stopwatch timer)
        {
            long ticks = timer.ElapsedTicks;
            if (ticks > 0)
                AddSample(ticks);
        }

        public TimeSpan GetSumTime()
        {
            return TimeSpan.FromMilliseconds((GetSum() * 1000) / Stopwatch.Frequency);
        }


        /// <summary>
        /// Returns the default (zero) value.
        /// </summary>
        /// <returns></returns>
        protected abstract T GetZero();

        /// <summary>
        /// Adds two values.
        /// </summary>
        protected abstract T Add(T a, T b);

        public void Reset()
        {
            ZeroBuckets(0, NumBuckets);
            curBucketGlobal = GetNow() / bucketSize;
            totalSum = GetZero();
            totalCount = 0;
        }


        public void Clear()
        {
            properties.Clear();
            buckets.Clear();
            elementCount = 0;
        }

        public void AddFloatProperty(string name)
        {
            properties.Add(new PropertyDesc()
            {
                Name = name,
                ComponentIndex = 0,
                ComponentName = name,
                Type = "float"
            });

            buckets.Add(new List<object>());
        }

        public void AddVector2Property(string name)
        {
            properties.Add(new PropertyDesc()
            {
                Name = name + ".x",
                ComponentIndex = 0,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".y",
                ComponentIndex = 1,
                ComponentName = name,
                Type = "float"
            });
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
        }

        public void AddVector3Property(string name)
        {
            properties.Add(new PropertyDesc()
            {
                Name = name + ".x",
                ComponentIndex = 0,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".y",
                ComponentIndex = 1,
                ComponentName = name,
                Type = "float"
            }); properties.Add(new PropertyDesc()
            {
                Name = name + ".z",
                ComponentIndex = 2,
                ComponentName = name,
                Type = "float"
            });
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
        }

        public void AddVector4Property(string name)
        {
            properties.Add(new PropertyDesc()
            {
                Name = name + ".x",
                ComponentIndex = 0,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".y",
                ComponentIndex = 1,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".z",
                ComponentIndex = 2,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".w",
                ComponentIndex = 3,
                ComponentName = name,
                Type = "float"
            });
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
        }

        public void AddColorProperty(string name)
        {
            properties.Add(new PropertyDesc()
            {
                Name = name + ".r",
                ComponentIndex = 0,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".g",
                ComponentIndex = 1,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".b",
                ComponentIndex = 2,
                ComponentName = name,
                Type = "float"
            });
            properties.Add(new PropertyDesc()
            {
                Name = name + ".a",
                ComponentIndex = 3,
                ComponentName = name,
                Type = "float"
            });
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
            buckets.Add(new List<object>());
        }

Google.Apis.Storage.v1.Data.Buckets : IDirectResponseSchema

Constructors :

public Buckets()

Methods :

public IList<Bucket> get_Items()
public Void set_Items(IList<Bucket> value = )
public String get_Kind()
public Void set_Kind(String value = )
public String get_NextPageToken()
public Void set_NextPageToken(String value = )
public String get_ETag()
public Void set_ETag(String value = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()