コード例 #1
0
        /// <summary>
        /// Initialize the list of buckets. Get the bucket sizes
        /// (and bucket lengths) from the bucket sizes provider.
        /// </summary>
        /// <param name="inUseCounts">
        /// Map of current buckets and their in use counts.
        /// </param>
        private void InitBuckets(Dictionary <int, int> inUseCounts)
        {
            lock (_poolGate)
            {
                Preconditions.CheckNotNull(inUseCounts);

                // Clear out all the buckets
                Buckets.Clear();

                // Create the new buckets
                Dictionary <int, int> bucketSizes = _poolParams.BucketSizes;
                if (bucketSizes != null)
                {
                    foreach (KeyValuePair <int, int> entry in bucketSizes)
                    {
                        int bucketSize       = entry.Key;
                        int maxLength        = entry.Value;
                        int bucketInUseCount = 0;
                        inUseCounts.TryGetValue(bucketSize, out bucketInUseCount);
                        Buckets.Add(bucketSize,
                                    new Bucket <T>(
                                        GetSizeInBytes(bucketSize),
                                        maxLength,
                                        bucketInUseCount));
                    }

                    _allowNewBuckets = false;
                }
                else
                {
                    _allowNewBuckets = true;
                }
            }
        }
コード例 #2
0
        public WorkBucket <TItem, TContext> AddBucket(string name, int nbWorker, TContext context)
        {
            WorkBucket <TItem, TContext> bucket = new WorkBucket <TItem, TContext>(context, name, Action, nbWorker);

            Buckets.Add(bucket);
            foreach (Worker <TItem, TContext> worker in bucket.Workers)
            {
                worker.PropertyChanged += WorkerOnPropertyChanged;
            }

            return(bucket);
        }
コード例 #3
0
        private async Task InitPlanAsync()
        {
            try
            {
                ClearTasks();
                GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync();

                if (graphClient != null)
                {
                    IPlannerPlanBucketsCollectionPage buckets = await graphClient.Planner.Plans[PlanId].Buckets.Request().GetAsync();
                    List <PlannerBucket> bucketList           = new List <PlannerBucket>();
                    while (true)
                    {
                        foreach (PlannerBucket bucket in buckets)
                        {
                            bucketList.Add(bucket);
                        }

                        if (buckets.NextPageRequest == null)
                        {
                            break;
                        }

                        buckets = await buckets.NextPageRequest.GetAsync();
                    }

                    TaskFilterSource.Clear();
                    Buckets.Clear();
                    TaskFilterSource.Add(new PlannerBucket {
                        Id = TaskTypeAllTasksId, Name = AllTasksLabel
                    });
                    foreach (PlannerBucket bucket in bucketList)
                    {
                        Buckets.Add(bucket);
                        TaskFilterSource.Add(bucket);
                    }

                    TaskFilterSource.Add(new PlannerBucket {
                        Id = TaskTypeClosedTasksId, Name = ClosedTasksLabel
                    });
                    TaskType = TaskTypeAllTasksId;
                    await LoadAllTasksAsync();
                }
            }
            catch (Exception exception)
            {
                MessageDialog messageDialog = new MessageDialog(exception.Message);
                await messageDialog.ShowAsync();
            }
        }
コード例 #4
0
        private Buckets GenerateBueckets(Individual individual)
        {
            var datasets = Datasets.Get();

            var buckets = new Buckets(datasets.TotalPeriods);

            for (int i = 0; i < datasets.TotalPeriods; ++i)
            {
                buckets.Add(new List <Chromosome>());
            }
            foreach (var chromo in individual.Genome)
            {
                buckets[chromo.Gene.TimeId].Add(chromo);
            }

            return(buckets);
        }
コード例 #5
0
        /// <summary>
        /// refresh the bucket list
        /// </summary>
        void RefreshBuckets()
        {
            //init buckets and files
            SelectedBucket = "";
            SelectedFile   = "";
            Buckets.Clear();
            Files.Clear();

            //get the buckets
            IEnumerable <string> buckets;

            if (!CloudStorage.GetBuckets(out buckets))
            {
                MessageBox.Show("There was an error getting buckets.");
                return;
            }
            //copy into our list
            buckets.ToList().ForEach(b => Buckets.Add(b));
        }
コード例 #6
0
        /// <summary>
        /// Gets the freelist for the specified bucket.
        /// Create the freelist if there isn't one.
        /// </summary>
        /// <param name="bucketedSize">The bucket size.</param>
        /// <returns>The freelist for the bucket.</returns>
        internal Bucket <T> GetBucket(int bucketedSize)
        {
            lock (_poolGate)
            {
                // Get an existing bucket
                Bucket <T> bucket = default(Bucket <T>);
                Buckets.TryGetValue(bucketedSize, out bucket);
                if (bucket != null || !_allowNewBuckets)
                {
                    return(bucket);
                }

                // Create a new bucket
#if DEBUG_MEMORY_POOL
                Debug.WriteLine($"Creating new bucket { bucketedSize }");
#endif // DEBUG_MEMORY_POOL
                Bucket <T> newBucket = NewBucket(bucketedSize);
                Buckets.Add(bucketedSize, newBucket);
                return(newBucket);
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates the bucket.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.String.</returns>
        private HttpStatusCode CreateBucket(CreateBucketRequest request)
        {
            try
            {
                request.BucketName = request.BucketName.ToLower();
                if (string.IsNullOrEmpty(request.BucketName))
                {
                    return(HttpStatusCode.BadRequest);
                }

                if (Buckets.ContainsKey(request.BucketName))
                {
                    return(HttpStatusCode.BadRequest);
                }

                Buckets.Add(request.BucketName, DataBucket.CreateNewBucket(request.BucketName, DbLocation, request.MaxRecordSize, request.MaxRecordsPerBin));
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
コード例 #8
0
ファイル: Engine.cs プロジェクト: DUAN-SEAN/CrazyFrameProject
        /// <summary>
        /// 根据Bound 粗测阶段
        /// </summary>
        /// <param name="bodies"></param>
        /// <param name="forceUpdate"></param>
        private void UpdateBroadphase(List <Body> bodies, bool forceUpdate)
        {
            var gridChanged = false;

            foreach (var body in bodies
                     .Where(body => forceUpdate || !body.Sleep)
                     .Where(
                         body =>
                         !(body.Bounds.Max.X < World.Bounds.Min.X) && !(body.Bounds.Min.X > World.Bounds.Max.X) &&
                         !(body.Bounds.Max.Y < World.Bounds.Min.Y) && !(body.Bounds.Min.Y > World.Bounds.Max.Y)))
            {
                var newRegion = GetRegion(body);
                if (body.Region == null || newRegion.GetId() != body.Bounds.GetId() || forceUpdate)
                {
                    if (body.Region == null || forceUpdate)
                    {
                        body.Region = newRegion;
                    }
                    var union = newRegion.Union(body.Region);
                    for (var x = union.Min.X; x <= union.Max.X; x++)
                    {
                        for (var y = union.Min.Y; y <= union.Max.Y; y++)
                        {
                            var bucketId          = x + "," + y;
                            var bucketExists      = Buckets.ContainsKey(bucketId);
                            var isInsideNewRegion = newRegion.Contains(x, y);
                            var isInsideOldRegion = body.Region.Contains(x, y);
                            if (!isInsideNewRegion && isInsideOldRegion)
                            {
                                if (bucketExists)
                                {
                                    var bucket = Buckets[bucketId];
                                    bucket.Remove(body);
                                    foreach (var pair in from _body in bucket
                                             select Helper.GetPairId(body, _body)
                                             into pairId
                                             where _tmpPairs.ContainsKey(pairId)
                                             select _tmpPairs[pairId])
                                    {
                                        pair.Count--;
                                    }
                                }
                            }
                            if (body.Region == newRegion || (isInsideNewRegion && !isInsideOldRegion) || forceUpdate)
                            {
                                var bucket = bucketExists ? Buckets[bucketId] : new List <Body>();
                                if (!bucketExists)
                                {
                                    Buckets.Add(bucketId, bucket);
                                }
                                foreach (var bodyB in bucket)
                                {
                                    if (body.Id.Value == bodyB.Id.Value || (body.Static && bodyB.Static))
                                    {
                                        continue;
                                    }
                                    var     pairId = Helper.GetPairId(body, bodyB);
                                    TmpPair pair;
                                    if (_tmpPairs.TryGetValue(pairId, out pair))
                                    {
                                        pair.Count++;
                                    }
                                    else
                                    {
                                        _tmpPairs.Add(pairId, new TmpPair(body, bodyB, 1));
                                    }
                                }
                                bucket.Add(body);
                            }
                        }
                    }
                    body.Region = newRegion;
                    gridChanged = true;
                }
            }
            if (gridChanged)
            {
                _tmpPairsList = _tmpPairs.Values.Where(x => x.Count > 0).ToList();
                _tmpPairs     = _tmpPairs.Where(x => x.Value.Count > 0).ToDictionary(x => x.Key, x => x.Value);
            }
        }
コード例 #9
0
 private void Add(Bucket bucket)
 {
     Buckets.Add(bucket);
     Buckets.Sort();
 }
コード例 #10
0
ファイル: Catalog.cs プロジェクト: melnx/Bermuda
        /// <summary>
        /// Initialize the buckets and catalog data table from metadata
        /// </summary>
        /// <returns></returns>
        public bool InitializeFromMetadata()
        {
            try
            {
                //catalog tables
                foreach (ITableMetadata table_metadata in CatalogMetadata.Tables.Values)
                {
                    //create our catalog level table
                    DataTable table;
                    if (table_metadata.ReferenceTable)
                    {
                        table = new ReferenceDataTable(this, table_metadata);
                    }
                    else
                    {
                        table = new CatalogDataTable(this, table_metadata);
                    }

                    //add to the catalog
                    CatalogDataTables.Add(table_metadata.TableName, table);
                }
                //buckets
                for (int x = 0; x < ComputeNode.GlobalBucketCount; x++)
                {
                    //check for our mod
                    if (x % ComputeNode.ComputeNodeCount == ComputeNode.ComputeNodeIndex)
                    {
                        //make a bucket
                        Bucket bucket = new Bucket(this);
                        Buckets.Add(x, bucket);
                        bucket.BucketMod = x;

                        //parse the metadata
                        foreach (ITableMetadata table_metadata in CatalogMetadata.Tables.Values.Where(t => t.ReferenceTable == false))
                        {
                            //create our bucket level table
                            IRelationshipMetadata relationship_metadata = CatalogMetadata.Relationships.Values.Where(r => r.RelationTable == table_metadata).FirstOrDefault();
                            IBucketDataTable      table;
                            if (relationship_metadata != null)
                            {
                                table = new RelationshipDataTable(bucket, table_metadata, relationship_metadata);
                            }
                            else
                            {
                                table = new BucketDataTable(bucket, table_metadata);
                            }

                            //add to our bucket
                            bucket.BucketDataTables.Add(table_metadata.TableName, table);
                        }
                    }
                }
                //mark as initialized
                Initialized = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
                return(false);
            }
            return(true);
        }