public Hash() { paginasArr = new List <Pagina>(); bucketContainer = new BucketContainer[51839]; acessoDisco = 0; colisoes = 0; }
public void DensityHintsAreEqualToDensities() { BucketContainer bucketContainer = _fixture.SampleEvents3; var densitiesBySeconds = bucketContainer.GetDensities(bucketContainer.FirstTimestamp, bucketContainer.LastTimestamp, Durations.Second); var densitiesByMinutes = bucketContainer.GetDensities(bucketContainer.FirstTimestamp, bucketContainer.LastTimestamp, Durations.Minute); _densityPrecalculationProcess.Complete(bucketContainer); var hints = bucketContainer.DensityHintContainer; Assert.NotNull(hints); Assert.Equal(densitiesBySeconds.Length, (int)hints.Seconds.Keys.Max()); Assert.Equal(densitiesByMinutes.Length, (int)hints.Minutes.Keys.Max()); foreach (var hint in hints.Seconds) { Assert.True(hint.Key >= 1); Assert.Equal(densitiesBySeconds[hint.Key - 1], hint.Value); } foreach (var hint in hints.Minutes) { Assert.True(hint.Key >= 1); Assert.Equal(densitiesByMinutes[hint.Key - 1], hint.Value); } }
public void PourTo(BucketContainer other) { var amount = Math.Min(other.Capacity - other.Contents, Contents); Contents -= amount; other.Contents += amount; }
private static void ShowChart(BucketContainer container, long start, long end, ushort chartWidth) { SegmentSize[] preferredSizes = container.GetPreferredSegmentSizes(start, end, chartWidth); if (preferredSizes.Length < 1) { throw new InvalidOperationException(); } long segmentSize = preferredSizes[preferredSizes.Length - 1].RequestedValue; end = start + segmentSize * chartWidth; Console.WriteLine("Here are densities for chart of width equal to {0}px", chartWidth); var densities = container.GetDensities(start, end, segmentSize); foreach (var density in densities) { Console.BackgroundColor = ConsoleColor.Black; Console.Write($"{{0,{7}:0.00}}% ", density * 100); Console.BackgroundColor = ConsoleColor.Gray; var percent = (int)(density * (Console.WindowWidth - 10)); for (var i = 1; i <= percent; i++) { Console.Write(' '); } Console.WriteLine(); } Console.WriteLine(); Console.BackgroundColor = ConsoleColor.Black; }
private static void RunPerfomanceTests(BucketContainer container, long start, long end, long[] segmentSizes) { bool isWarmUp = true; int tries = 0; while (tries < 2) { var stopWatch = new Stopwatch(); foreach (var segmentSize in segmentSizes) { long tStart = start, tEnd = Math.Min(start + segmentSize * 4000, end); stopWatch.Start(); var densities = container.GetDensities(tStart, tEnd, segmentSize); var elapsed = stopWatch.ElapsedMilliseconds; stopWatch.Reset(); if (!isWarmUp) { Console.WriteLine("Segment size {0,10}: {1,4}ms elapsed for the range with length {2}μs: average density = {3}", segmentSize, elapsed, tEnd - tStart, densities.Average()); } } tries++; isWarmUp = false; } }
public void Complete(BucketContainer container) { foreach (var process in _processes) { process.Complete(container); } }
private void EventsChartArea_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { var position = e.GetPosition(this); long start = _firstTimestamp + Offset + (long)(SegmentSize.DisplayedValue * position.X); long end = start + SegmentSize.DisplayedValue + 1; var payloads = BucketContainer.GetPayloads(start, end); _tooltip.Show(position.X, position.Y, payloads.Count); }
public ChartWindow(BucketContainer bucketContainer) { BucketContainer = bucketContainer; InitializeComponent(); _timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 3), IsEnabled = true }; _timer.Tick += (obj, args) => HideZoomInfo(); }
protected override void ProcessRecord() { if (ModuleVars._account == null) { ThrowTerminatingError(new ErrorRecord(new FieldAccessException("Please run Connect-B2Cloud to authenticate."), "B2AccountNotAuthenticated", ErrorCategory.AuthenticationError, null)); } BucketContainer bucketData = B2Functions.ListBuckets(ModuleVars._account); foreach (Bucket i in bucketData) { WriteObject(i); } }
public void adicionarHash(string nome, int id, int linha) { int hashLogic = amazingHashLogic(nome); if (bucketContainer[hashLogic] == null) { bucketContainer[hashLogic] = new BucketContainer(new BucketObjeto(nome, id, linha)); } else { bucketContainer[hashLogic].adicionar(new BucketObjeto(nome, id, linha)); colisoes++; bucketContainer[hashLogic].colisao++; } }
public void DensityHintsCountIsCorrect() { BucketContainer bucketContainer = _fixture.SampleEvents3; _densityPrecalculationProcess.Complete(bucketContainer); var hints = bucketContainer.DensityHintContainer; Assert.NotNull(hints); var totalDuration = bucketContainer.LastTimestamp - bucketContainer.FirstTimestamp; Assert.Equal(Math.Ceiling(totalDuration / (double)Durations.Second), (int)hints.Seconds.Keys.Max()); Assert.Equal(Math.Ceiling(totalDuration / (double)Durations.Minute), (int)hints.Minutes.Keys.Max()); }
public void Complete(BucketContainer container) { if (_isCompleted) { return; } ProcessNewBuckets(new ArraySegment <Bucket>(container.Buckets), true); container.DensityHintContainer = new DensityHintContainer( _densityHintsForSeconds, _densityHintsForMinutes ); _isCompleted = true; }
private Task <BucketContainer> StartProcessingEventsWithPipeline( IEventReader reader, IProgress <int> progress) { var tcs = new TaskCompletionSource <BucketContainer>(); var thread = new Thread(() => { try { var bucketsList = new ResizableArray <Bucket>(); double processedEventsCount = 0; int bucketCount = 0; foreach (var bucket in reader.GetAllBuckets()) { processedEventsCount += bucket.Events.Length; bucketsList.Add(bucket); _eventProcessor.ProcessBucket(bucketsList.GetArraySegment(), bucketCount); if (reader.TotalEventsCount > 0) { progress.Report((int)Math.Min(processedEventsCount / reader.TotalEventsCount * 100, 100)); } bucketCount++; } progress.Report(100); var buckets = bucketsList.ToArray(); bucketsList = null; var container = new BucketContainer(buckets, reader.FirstTimestamp); _eventProcessor.Complete(container); tcs.SetResult(container); } catch (TaskCanceledException) { tcs.SetCanceled(); } catch (Exception exc) { tcs.SetException(exc); } }); thread.Start(); return(tcs.Task); }
public static BucketContainer ListBuckets(Account account) { var client = new RestClient() { BaseUrl = new Uri(account.ApiUri) }; var req = new RestRequest() { Method = Method.POST, Resource = "/b2api/v1/b2_list_buckets", RequestFormat = DataFormat.Json }; req.AddHeader("Authorization", account.AuthorizationToken); req.AddJsonBody(new Dictionary <string, string> { ["accountId"] = account.AccountId }); BucketContainer data = client.Execute <BucketContainer>(req).Data; return(data); }
private static void DisplayValidPayloads(BucketContainer container, long start, long end) { var payloads = container.GetPayloads(start, end); Console.WriteLine("There are {0} payloads in your range (display limit is 100 payloads):", payloads.Count); int count = 0; foreach (ref readonly Payload payload in payloads) { if (++count <= 100) { Console.WriteLine("{0}. Payload: {1}, {2}, {3}, {4}", count, payload.First, payload.Second, payload.Third, payload.Fourth); } } Console.WriteLine("...Total: {0}", count); }
public void GlobalSetup() { try { var eventsApi = new ApiFacade { ProgressHandler = new ConsoleProgress() }; var filePath = Environment.GetEnvironmentVariable(FilePathEnvVariable); BucketContainer = eventsApi.LoadEventsFromFileAsync(filePath, LoadStrategyType.LoadEventsAndPayloadsForChart) .GetAwaiter() .GetResult(); var lastBucket = BucketContainer.GetLastBucket(); Start = BucketContainer.FirstTimestamp; End = lastBucket?.GetAbsoluteTimeForEvent(lastBucket.GetLastEvent()) ?? 0; } catch (Exception exc) { Console.WriteLine(); Console.WriteLine(exc.ToString()); } }
public FigureDataAdapterForApi(BucketContainer container, double[] targetBuffer) { _container = container; _targetBuffer = targetBuffer; }
public TwoBuckets(int bucketOneSize, int bucketTwoSize, Bucket startBucket) { bucketOne = new BucketContainer(startBucket == Bucket.One ? bucketOneSize : 0, bucketOneSize); bucketTwo = new BucketContainer(startBucket == Bucket.Two ? bucketTwoSize : 0, bucketTwoSize); strategy = startBucket == Bucket.One ? (Action)StartFromFirstBucket : StartFromSecondBucket; }
public bool CanPourTo(BucketContainer other) => !IsEmpty && !other.IsFull;
public void Complete(BucketContainer container) { }
private void InitializeChartArea() { _targetBufferForDensities = BucketContainer.CreateBufferForDensities(); _firstTimestamp = BucketContainer.FirstTimestamp; _figureDataAdapter = new FigureDataAdapterForApi(BucketContainer, _targetBufferForDensities); }
private static void ShowCharts(BucketContainer container, long start, long end) { ShowChart(container, start, end, 60); ShowChart(container, start, end, 120); }
public InteractiveUserMode(InteractiveModeType interactiveModeType, BucketContainer bucketContainer) { InteractiveModeType = interactiveModeType; BucketContainer = bucketContainer; }
/// <summary> /// Gets densities for segments with size equal to <paramref name="segmentSize"/> /// </summary> /// <param name="container">Bucket container</param> /// <param name="start">Start time</param> /// <param name="end">End time</param> /// <param name="segmentSize">Length/duration of one segment</param> /// <param name="targetBuffer">Targer buffer into which calculated densities are saved</param> /// <returns></returns> public static Span <double> GetDensities(BucketContainer container, long start, long end, long segmentSize, ref double[] targetBuffer) { if (end <= start) { throw new ArgumentException("Wrong interval. End timestamp must be greater than start timestamp."); } if (end - start < segmentSize) { throw new ArgumentException("Segment size is too big for this time interval", nameof(segmentSize)); } var lastBucket = container.GetLastBucket(); var maxTime = lastBucket.GetAbsoluteTimeForEvent(lastBucket.GetLastEvent()); if (end > maxTime + 1) { end = maxTime + 1; } // Start time is out of range if (end < start) { return(Span <double> .Empty); } ushort totalSegments = GetTotalSegments(start, end, segmentSize); if (targetBuffer == null) { targetBuffer = new double[totalSegments]; } else if (targetBuffer.Length < totalSegments) { throw new ArgumentException("Target buffer is too short", nameof(targetBuffer)); } int processedSegmentsUsingHints = -1; try { checked { container.DensityHintContainer?.TrySetDensitiesUsingHints( start - container.FirstTimestamp, end - container.FirstTimestamp, segmentSize, targetBuffer, out processedSegmentsUsingHints ); } } catch (OverflowException) { throw new InvalidOperationException("Too big range of events"); } #if DEBUG if (processedSegmentsUsingHints == 0 && segmentSize >= 10_000_000) { Debug.Fail("Density calculation is perfoming in unoptimized way. It can be eliminated by adjusting range and segment size to appropriate values."); } #endif if (processedSegmentsUsingHints < 0) { processedSegmentsUsingHints = 0; } if (processedSegmentsUsingHints == totalSegments) { return(targetBuffer.AsSpan(0, totalSegments)); } start += processedSegmentsUsingHints * segmentSize; int uncalculatedDensitiesCount = totalSegments - processedSegmentsUsingHints; var targetBufferCopy = targetBuffer; Parallel.ForEach(GetPartitions(start, segmentSize, targetBuffer.AsSpan(processedSegmentsUsingHints, uncalculatedDensitiesCount)), (partition) => { Span <double> batch = targetBufferCopy.AsSpan(processedSegmentsUsingHints, uncalculatedDensitiesCount) .Slice(partition.leftBoundary, partition.batchLength); DensityCalculator.CalculateDensities( container.Buckets, new DensityCalculationRequest(partition.start, partition.end, segmentSize), batch, true, out long processedRange ); }); return(targetBuffer.AsSpan(0, totalSegments)); }
/// <summary> /// Gets densities for segments with size equal to <paramref name="segmentSize"/> /// </summary> /// <param name="container">Bucket container</param> /// <param name="start">Start time</param> /// <param name="end">End time</param> /// <param name="segmentSize">Length/duration of one segment</param> public static double[] GetDensities(BucketContainer container, long start, long end, long segmentSize) { double[] densities = null; GetDensities(container, start, end, segmentSize, targetBuffer: ref densities); return(densities ?? Array.Empty <double>()); }
public bool CanPourTo(BucketContainer other) => IsFull && !other.IsFull || !IsFull && other.IsEmpty;