| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library chat_server; | 5 library chat_server; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
| 10 import 'dart:math'; | 10 import 'dart:math'; |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 // range is split over a number of buckets where each bucket collects | 632 // range is split over a number of buckets where each bucket collects |
| 633 // the number of events happening in that time sub-range. The first | 633 // the number of events happening in that time sub-range. The first |
| 634 // constructor arument specifies the time range in milliseconds. The | 634 // constructor arument specifies the time range in milliseconds. The |
| 635 // buckets are in the list _buckets organized at a circular buffer | 635 // buckets are in the list _buckets organized at a circular buffer |
| 636 // with _currentBucket marking the bucket where an event was last | 636 // with _currentBucket marking the bucket where an event was last |
| 637 // recorded. A current sum of the content of all buckets except the | 637 // recorded. A current sum of the content of all buckets except the |
| 638 // one pointed a by _currentBucket is kept in _sum. | 638 // one pointed a by _currentBucket is kept in _sum. |
| 639 class Rate { | 639 class Rate { |
| 640 Rate([int timeRange = 1000, int buckets = 10]) | 640 Rate([int timeRange = 1000, int buckets = 10]) |
| 641 : _timeRange = timeRange, | 641 : _timeRange = timeRange, |
| 642 _buckets = new List(buckets + 1), // Current bucket is not in the sum. | 642 _buckets = new List.fixedLength(buckets + 1), // Current bucket is not
in the sum. |
| 643 _currentBucket = 0, | 643 _currentBucket = 0, |
| 644 _currentBucketTime = new Date.now().millisecondsSinceEpoch, | 644 _currentBucketTime = new Date.now().millisecondsSinceEpoch, |
| 645 _sum = 0 { | 645 _sum = 0 { |
| 646 _bucketTimeRange = (_timeRange / buckets).toInt(); | 646 _bucketTimeRange = (_timeRange / buckets).toInt(); |
| 647 for (int i = 0; i < _buckets.length; i++) { | 647 for (int i = 0; i < _buckets.length; i++) { |
| 648 _buckets[i] = 0; | 648 _buckets[i] = 0; |
| 649 } | 649 } |
| 650 } | 650 } |
| 651 | 651 |
| 652 // Record the specified number of events. | 652 // Record the specified number of events. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 685 } |
| 686 } | 686 } |
| 687 | 687 |
| 688 int _timeRange; | 688 int _timeRange; |
| 689 List<int> _buckets; | 689 List<int> _buckets; |
| 690 int _currentBucket; | 690 int _currentBucket; |
| 691 int _currentBucketTime; | 691 int _currentBucketTime; |
| 692 num _bucketTimeRange; | 692 num _bucketTimeRange; |
| 693 int _sum; | 693 int _sum; |
| 694 } | 694 } |
| OLD | NEW |