/// <summary> /// Creates a new instance by deserializing. /// </summary> public static Buckets Deserialize(BinaryReader reader) { Contract.Requires(reader != null); int capacity = reader.ReadInt32(); int lastBucketIndex = reader.ReadInt32(); int pendingSplitBucketCount = reader.ReadInt32(); int preSplitBucketsLength = reader.ReadInt32(); int isSplitting = reader.ReadInt32(); int splitThreshold = reader.ReadInt32(); int splitBucketCursor = reader.ReadInt32(); byte[] buffer = null; var buckets = new Buckets( bucketsBufferInitializer: (bufferStart, bufferCount) => { if (bufferStart + bufferCount > capacity) { throw new IOException("Unsupported format"); } return(reader.ReadInt32Array(ref buffer, bufferCount)); }, capacity: capacity, lastBucketIndex: lastBucketIndex, pendingSplitBucketCount: pendingSplitBucketCount, preSplitBucketsLength: preSplitBucketsLength, isSplitting: isSplitting, splitThreshold: splitThreshold, splitBucketCursor: splitBucketCursor); return(buckets); }
public HistogramConfiguration(string name, string help, bool includeTimestamp, string[] labels, double[] buckets) : base(name, help, includeTimestamp, labels) { Buckets = buckets ?? _defaultBuckets; if (LabelNames.Any(l => l == "le")) { throw new ArgumentException("'le' is a reserved label name"); } if (Buckets.Count == 0) { throw new ArgumentException("Histogram must have at least one bucket"); } if (!double.IsPositiveInfinity(Buckets[Buckets.Count - 1])) { Buckets = Buckets.Concat(new[] { double.PositiveInfinity }).ToArray(); } for (int i = 1; i < Buckets.Count; i++) { if (Buckets[i] <= Buckets[i - 1]) { throw new ArgumentException("Bucket values must be increasing"); } } FormattedBuckets = Buckets .Select(b => b.ToString(CultureInfo.InvariantCulture)) .ToArray(); }
public void Sort(ref int[] array) { _positionalNumber = SetNumberLength(array); for (int i = 1; i <= _positionalNumber; i++) { Buckets tmpBuckets = new Buckets(); for (int j = 0; j < array.Length; j++) { string tmpToString = array[j].ToString(); if (tmpToString.Length < i) { tmpBuckets.InputBucket(0, array[j]); } else { tmpBuckets.InputBucket(int.Parse(tmpToString[tmpToString.Length - i].ToString()), array[j]); } } array = tmpBuckets.GetArray(); } }
public void TestToBody() { TeaModel modelNull = new TeaModel(); Assert.Empty((string)TestHelper.RunInstanceMethod(typeof(BaseClient), "_toXML", baseClient, new object[] { modelNull })); ToBodyModel model = new ToBodyModel(); ListAllMyBucketsResult result = new ListAllMyBucketsResult(); Buckets buckets = new Buckets(); buckets.bucket = new List <Bucket>(); buckets.bucket.Add(new Bucket { CreationDate = "2015-12-17T18:12:43.000Z", ExtranetEndpoint = "oss-cn-shanghai.aliyuncs.com", IntranetEndpoint = "oss-cn-shanghai-internal.aliyuncs.com", Location = "oss-cn-shanghai", Name = "app-base-oss", StorageClass = "Standard" }); buckets.bucket.Add(new Bucket { CreationDate = "2014-12-25T11:21:04.000Z", ExtranetEndpoint = "oss-cn-hangzhou.aliyuncs.com", IntranetEndpoint = "oss-cn-hangzhou-internal.aliyuncs.com", Location = "oss-cn-hangzhou", Name = "atestleo23", StorageClass = "IA" }); buckets.bucket.Add(null); result.buckets = buckets; Owner owner = new Owner { ID = 512, DisplayName = "51264" }; result.owner = owner; model.listAllMyBucketsResult = result; model.listAllMyBucketsResult.testStrList = new List <string> { "1", "2" }; model.listAllMyBucketsResult.owners = new List <Owner>(); model.listAllMyBucketsResult.owners.Add(owner); model.listAllMyBucketsResult.TestDouble = 1; model.listAllMyBucketsResult.TestFloat = 2; model.listAllMyBucketsResult.TestLong = 3; model.listAllMyBucketsResult.TestShort = 4; model.listAllMyBucketsResult.TestUInt = 5; model.listAllMyBucketsResult.TestULong = 6; model.listAllMyBucketsResult.TestUShort = 7; model.listAllMyBucketsResult.TestBool = true; model.listAllMyBucketsResult.TestNull = null; model.listAllMyBucketsResult.TestListNull = null; string xmlStr = (string)TestHelper.RunInstanceMethod(typeof(BaseClient), "_toXML", baseClient, new object[] { model }); Assert.NotNull(xmlStr); Mock <HttpWebResponse> mockHttpWebResponse = new Mock <HttpWebResponse>(); mockHttpWebResponse.Setup(p => p.StatusCode).Returns(HttpStatusCode.OK); mockHttpWebResponse.Setup(p => p.StatusDescription).Returns("StatusDescription"); mockHttpWebResponse.Setup(p => p.Headers).Returns(new WebHeaderCollection()); byte[] array = Encoding.UTF8.GetBytes(xmlStr); MemoryStream stream = new MemoryStream(array); mockHttpWebResponse.Setup(p => p.GetResponseStream()).Returns(stream); TeaResponse teaResponse = new TeaResponse(mockHttpWebResponse.Object); Dictionary <string, object> xmlBody = (Dictionary <string, object>)TestHelper.RunInstanceMethod(typeof(BaseClient), "_parseXml", baseClient, new object[] { xmlStr, typeof(ToBodyModel) }); ToBodyModel teaModel = TeaModel.ToObject <ToBodyModel>(xmlBody); Assert.NotNull(teaModel); Assert.Equal(1, teaModel.listAllMyBucketsResult.TestDouble); }
/// <summary> /// create a new bucket in cloud /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btNewBucket_Click(object sender, RoutedEventArgs e) { //create the bucket InputWindow dlg = new InputWindow("New Bucket", "Enter the new bucket name."); var ret = dlg.ShowDialog(); if (!ret.HasValue || ret.Value == false) { return; } //check the return string name = dlg.Questions[0].Answer; if (name.IndexOf(' ') != -1) { MessageBox.Show("The new bucket name can not contain spaces."); return; } else if (Buckets.Any(b => b.Equals(name, StringComparison.InvariantCultureIgnoreCase))) { MessageBox.Show("There is already a bucket with the name: " + name); return; } //create new directory if (!CloudStorage.NewDirectory(name)) { MessageBox.Show("There was an error creating the bucket."); return; } //refresh the bucket list RefreshBuckets(); }
/// <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; } } }
public ICollection <Node> GetClosest(NodeId target) { var closestNodes = new ClosestNodesCollection(target); // Buckets have a capacity of 8 and are split in two whenever they are // full. As such we should always be able to find the 8 closest nodes // by adding the nodes of the matching bucket, the bucket above, and the // bucket below. int firstBucketIndex = Buckets.FindIndex(t => t.CanContain(target)); foreach (Node node in Buckets[firstBucketIndex].Nodes) { closestNodes.Add(node); } // Try the bucket before this one if (firstBucketIndex > 0) { foreach (Node node in Buckets[firstBucketIndex - 1].Nodes) { closestNodes.Add(node); } } // Try the bucket after this one if (firstBucketIndex < (Buckets.Count - 1)) { foreach (Node node in Buckets[firstBucketIndex + 1].Nodes) { closestNodes.Add(node); } } return(closestNodes); }
protected override void ProcessRecord() { base.ProcessRecord(); if (ParameterSetName == ParameterSetNames.SingleBucket) { BucketsResource.GetRequest req = Service.Buckets.Get(Name); req.Projection = BucketsResource.GetRequest.ProjectionEnum.Full; try { Bucket bucket = req.Execute(); WriteObject(bucket); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { ErrorRecord errorRecord = new ErrorRecord( new ItemNotFoundException($"Storage bucket '{Name}' does not exist."), "BucketNotFound", ErrorCategory.ObjectNotFound, Name); ThrowTerminatingError(errorRecord); } } if (ParameterSetName == ParameterSetNames.BucketsByProject) { var req = Service.Buckets.List(Project); req.Projection = BucketsResource.ListRequest.ProjectionEnum.Full; Buckets buckets = req.Execute(); WriteObject(buckets.Items, true); } }
private async void btnRefreshToken_Click(object sender, EventArgs e) { treeBuckets.Nodes.Clear(); BucketsApi bucketApi = new BucketsApi(); bucketApi.Configuration.AccessToken = AccessToken; // control GetBucket pagination string lastBucket = null; Buckets buckets = null; do { buckets = (await bucketApi.GetBucketsAsync(cmbRegion.Text, 100, lastBucket)).ToObject <Buckets>(); foreach (var bucket in buckets.Items) { TreeNode nodeBucket = new TreeNode(bucket.BucketKey); nodeBucket.Tag = bucket.BucketKey; treeBuckets.Nodes.Add(nodeBucket); lastBucket = bucket.BucketKey; // after the loop, this will contain the last bucketKey } } while (buckets.Items.Count > 0); // for each bucket, show the objects foreach (TreeNode n in treeBuckets.Nodes) { if (n != null) // async? { await ShowBucketObjects(n); } } }
private bool Add(Node node, bool raiseNodeAdded) { if (node == null) { throw new ArgumentNullException(nameof(node)); } var bucket = Buckets.Find(b => b.CanContain(node)); if (bucket.Nodes.Contains(node)) { return(false); } var added = bucket.Add(node); if (added && raiseNodeAdded) { RaiseNodeAdded(node); } if (!added && bucket.CanContain(LocalNode)) { if (Split(bucket)) { return(Add(node, raiseNodeAdded)); } } return(added); }
/// <summary> /// Retrieves all buckets from the specified project and adding them to the blocking collection. /// </summary> /// <param name="project">Project to retrieve buckets from.</param> /// <param name="collections">Blocking collection to add buckets to.</param> private static async Task ListBucketsAsync(Project project, BlockingCollection <Bucket> collections) { // Using a new service on every request here ensures they can all be handled at the same time. BucketsResource.ListRequest request = GetNewService().Buckets.List(project.ProjectId); var allBuckets = new List <Bucket>(); try { do { Buckets buckets = await request.ExecuteAsync(); if (buckets.Items != null) { foreach (Bucket bucket in buckets.Items) { // BlockingCollecton does not have AddRange so we have to add each item individually. collections.Add(bucket); } } request.PageToken = buckets.NextPageToken; } while (request.PageToken != null); } catch (GoogleApiException e) when(e.HttpStatusCode == HttpStatusCode.Forbidden) { } }
public void TestBucketsIncrementAndGetAndSet() { var b = new Buckets(5, 2); var incrementedB = b.Increment(0, 1); Assert.AreSame(b, incrementedB, "Returned Buckets should be the same instance"); var v = b.Get(0); Assert.AreEqual(1u, v); b.Increment(1u, -1); v = b.Get(1); Assert.AreEqual(0u, v); var setB = b.Set(2u, 100); Assert.AreSame(b, setB, "Returned Buckets should be the same instance"); v = b.Get(2); Assert.AreEqual(3u, v); b.Increment(3, 2); v = b.Get(3); Assert.AreEqual(2u, v); }
public HistogramConfiguration(string name, string help, IReadOnlyList <string> labels, IReadOnlyList <double> buckets, MetricFlags options) : base(name, help, labels, options) { Buckets = buckets ?? _defaultBuckets; if (LabelNames.Any(l => l == "le")) { throw new ArgumentException("'le' is a reserved label name"); } if (Buckets.Count == 0) { throw new ArgumentException("Histogram must have at least one bucket"); } if (!double.IsPositiveInfinity(Buckets[Buckets.Count - 1])) { Buckets = Buckets.Concat(_positiveInf).ToArray(); } for (int i = 1; i < Buckets.Count; i++) { if (Buckets[i] <= Buckets[i - 1]) { throw new ArgumentException("Bucket values must be increasing"); } } FormattedBuckets = Buckets .Select(b => b.ToString(CultureInfo.InvariantCulture)) .ToArray(); }
/// <summary> /// Returns true if the contact, by ID, exists in our bucket list. /// </summary> public bool ContactExists(Contact sender) { lock (this) { return(Buckets.SelectMany(b => b.Contacts).Any(c => c.ID == sender.ID)); } }
/// <inheritdoc/> protected async override void OnApplyTemplate() { ClearTasks(); Buckets.Clear(); Plans.Clear(); if (_list != null) { _list.ItemClick -= List_ItemClick; _list.Tapped += List_Tapped; if (_isPreviewKeyUpEventSupported) { _list.PreviewKeyUp -= List_PreviewKeyUp; } } if (_add != null) { _add.Click -= Add_Click; } if (_input != null) { _input.KeyUp -= Input_KeyUp; } base.OnApplyTemplate(); if (GetTemplateChild(ControlTasks) is ListView list) { _list = list; _list.ItemClick += List_ItemClick; _list.Tapped += List_Tapped; if (_isPreviewKeyUpEventSupported) { _list.PreviewKeyUp += List_PreviewKeyUp; } } if (GetTemplateChild(ControlAdd) is Button add) { _add = add; _add.Click += Add_Click; } _input = GetTemplateChild(ControlInput) as TextBox; if (_input != null) { _input.KeyUp += Input_KeyUp; } if (MicrosoftGraphService.Instance.IsAuthenticated) { await LoadPlansAsync(); } else { MicrosoftGraphService.Instance.IsAuthenticatedChanged -= Instance_IsAuthenticatedChanged; MicrosoftGraphService.Instance.IsAuthenticatedChanged += Instance_IsAuthenticatedChanged; } }
public Buckets <int> Run(Buckets <int> buckets) { var leftValue = buckets.Get(_leftBucket); var rightValue = buckets.Get(_rightBucket); return(buckets.Set(_outBucket, leftValue - rightValue)); }
public bool Equals(DestinyVendorInventoryFlyoutDefinition input) { if (input == null) { return(false); } return (( LockedDescription == input.LockedDescription || (LockedDescription != null && LockedDescription.Equals(input.LockedDescription)) ) && ( DisplayProperties == input.DisplayProperties || (DisplayProperties != null && DisplayProperties.Equals(input.DisplayProperties)) ) && ( Buckets == input.Buckets || (Buckets != null && Buckets.SequenceEqual(input.Buckets)) ) && ( FlyoutId == input.FlyoutId || (FlyoutId.Equals(input.FlyoutId)) ) && ( SuppressNewness == input.SuppressNewness || (SuppressNewness != null && SuppressNewness.Equals(input.SuppressNewness)) ) && ( EquipmentSlotHash == input.EquipmentSlotHash || (EquipmentSlotHash.Equals(input.EquipmentSlotHash)) )); }
/// <summary> /// Creates and returns set by deserialization /// </summary> /// <param name="reader">general reader</param> /// <param name="itemReader">item reader</param> /// <param name="concurrencyLevel">the concurrency level (all values less than 1024 will be assumed to be 1024)</param> public static ConcurrentBigSet <TItem> Deserialize( BinaryReader reader, Func <TItem> itemReader, int concurrencyLevel = DefaultConcurrencyLevel) { var count = reader.ReadInt32(); var nodeLength = reader.ReadInt32(); var itemsPerBufferBitWidth = reader.ReadInt32(); var capacity = Math.Max(MinConcurrencyLevel, Math.Max(nodeLength, concurrencyLevel)); var items = new BigBuffer <TItem>(itemsPerBufferBitWidth); items.Initialize(capacity); var nodes = new BigBuffer <Node>(NodesPerEntryBufferBitWidth); nodes.Initialize(capacity); var itemsAccessor = items.GetAccessor(); var nodesAccessor = nodes.GetAccessor(); List <int> freeNodes = new List <int>(); for (int i = 0; i < nodeLength; i++) { var hashCode = reader.ReadInt32(); if (hashCode != Node.UnusedHashCode) { var next = reader.ReadInt32(); var item = itemReader(); nodesAccessor[i] = new Node(hashCode, next); itemsAccessor[i] = item; } else { freeNodes.Add(i); } } var buckets = Buckets.Deserialize(reader); var result = new ConcurrentBigSet <TItem>( concurrencyLevel, items, nodes, buckets, nodeLength); result.m_count = count; // distribute free nodes var accessors = result.m_accessors; foreach (var i in freeNodes) { var lockNo = result.GetLockNo(i); result.AddFreeNode(lockNo, i, ref accessors); } return(result); }
/// <summary> /// This function is used to query the data source for records. /// </summary> /// <param name="alias">The Alias of the requested entity.</param> /// <returns>EntityCollection<EndPointAliasEntity></returns> public static EntityCollection <EndPointAliasEntity> Select(int section, System.String alias) { EntityCollection <EndPointAliasEntity> endpoints = new EntityCollection <EndPointAliasEntity>(); DataAccessAdapter ds = new DataAccessAdapter(); ds.FetchEntityCollection(endpoints, Buckets.GetForPK(section, alias)); return(endpoints); }
public void Delete(Buckets buckets) { /*var bucket = JsonConvert.SerializeObject(buckets); * var buffer = Encoding.UTF8.GetBytes(bucket); * var byteContent = new ByteArrayContent(buffer); * byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); * _client.DeleteAsync($"/storage/deleteFile", byteContent);*/ }
public void TestBucketsCount() { var b = new Buckets(10, 2); var count = b.count; Assert.AreEqual(10u, count); }
public void TestMaxBucketValue() { var b = new Buckets(10, 2); var max = b.MaxBucketValue(); Assert.AreEqual(3, max); }
public void LinearBuckets() { var buckets = Buckets.Linear(1, 2, 3); Assert.Equal( new double[] { 1, 3, 5 }, buckets ); }
/** Initialize your data structure here. */ public MyHashMap() { buckets = new Buckets[1000]; for (int i = 0; i < 1000; i++) { buckets[i] = new Buckets(); } }
public void ExponentialBuckets() { var buckets = Buckets.Exponential(2, 2.5, 3); Assert.Equal( new double[] { 2, 5, 12.5 }, buckets ); }
/// <summary> /// After insert, checks whether a split should be initiated and whether there are buckets which need to be split /// </summary> private void PerformPostInsertSplitOperations(ref Accessors accessors, int count) { // If necessary, trigger a split. if (Buckets.GrowIfNecessary(ref m_buckets, count)) { return; } int splitBucketNo; int targetBucketNo; if (m_buckets.TryGetBucketToSplit(out splitBucketNo, out targetBucketNo)) { // Only need to get lock for split bucket since target bucket // will always use the same lock int splitLockNo = GetLockNo(splitBucketNo); using (var writeLock = m_locks.AcquireWriteLock(splitLockNo, allowReads: true)) { var nodeIndex = m_buckets[splitBucketNo]; if (nodeIndex >= 0) { // We only need to exclude reads if the bucket actually has nodes which may need to be split. writeLock.ExcludeReads(); } int lastSplitNodeIndex = -3; int lastTargetNodeIndex = -3; while (nodeIndex >= 0) { var node = accessors.Nodes[nodeIndex]; var nextNodeIndex = node.Next; int bucketNo = m_buckets.GetBucketNo(node.Hashcode); Node newNode; if (bucketNo == splitBucketNo) { newNode = new Node(node.Hashcode, lastSplitNodeIndex); lastSplitNodeIndex = nodeIndex; } else { newNode = new Node(node.Hashcode, lastTargetNodeIndex); lastTargetNodeIndex = nodeIndex; } accessors.Nodes[nodeIndex] = newNode; nodeIndex = nextNodeIndex; } m_buckets.SetBucketHeadNodeIndexDirect(splitBucketNo, lastSplitNodeIndex); m_buckets.SetBucketHeadNodeIndexDirect(targetBucketNo, lastTargetNodeIndex); m_buckets.EndBucketSplit(); } } }
private void RegisterCriteria(Individual individual, Buckets buckets) { mCriteria = new List <ICriterion>(); mCriteria.Add(new TimeCheck(individual, buckets)); mCriteria.Add(new RoomCheck(individual, buckets)); mCriteria.Add(new TeacherCheck(individual)); mCriteria.Add(new ProgressCheck(individual)); }
public void BenchmarkBucketsIncrement() { var buckets = new Buckets(10000, 10); for (uint i = 0; i < buckets.count; i++) { buckets.Increment(i % 10000, 1); } }
public void SaveImage(Buckets buckets) { var bucket = JsonConvert.SerializeObject(buckets); var buffer = Encoding.UTF8.GetBytes(bucket); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); _client.PostAsync($"/storage/uploadFile", byteContent); }
public bool DeepEquals(VendorInventoryFlyout other) { return(other != null && LockedDescription == other.LockedDescription && DisplayProperties.DeepEquals(other.DisplayProperties) && Buckets.DeepEqualsReadOnlyCollections(other.Buckets) && SuppressNewness == other.SuppressNewness && FlyoutId == other.FlyoutId && EquipmentSlot.DeepEquals(other.EquipmentSlot)); }
static SignatureGenerator() { buckets = new Buckets(); }