Skip to content

Commit 0bcd2f7

Browse files
authored
seal (#225)
* seal * comments
1 parent 3796d9d commit 0bcd2f7

File tree

10 files changed

+21
-53
lines changed

10 files changed

+21
-53
lines changed

BitFaster.Caching/Buffers/MpmcBoundedBuffer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Drawing;
53
using System.Runtime.InteropServices;
6-
using System.Text;
74
using System.Threading;
85

96
namespace BitFaster.Caching.Buffers
@@ -16,7 +13,7 @@ namespace BitFaster.Caching.Buffers
1613
/// Based on the Segment internal class from ConcurrentQueue
1714
/// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs
1815
/// </remarks>
19-
public class MpmcBoundedBuffer<T>
16+
public sealed class MpmcBoundedBuffer<T>
2017
{
2118
private Slot[] slots;
2219
private readonly int slotsMask;

BitFaster.Caching/Buffers/MpscBoundedBuffer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Text;
53
using System.Threading;
6-
using System.Threading.Tasks;
74

85
namespace BitFaster.Caching.Buffers
96
{
@@ -16,7 +13,7 @@ namespace BitFaster.Caching.Buffers
1613
/// https://github.com/ben-manes/caffeine/blob/master/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedBuffer.java
1714
/// </remarks>
1815
[DebuggerDisplay("Count = {Count}/{Capacity}")]
19-
public class MpscBoundedBuffer<T> where T : class
16+
public sealed class MpscBoundedBuffer<T> where T : class
2017
{
2118
private T[] buffer;
2219
private readonly int mask;

BitFaster.Caching/Buffers/StripedMpmcBuffer.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Collections.Specialized;
4-
using System.Runtime.InteropServices;
2+
53
#if !NETSTANDARD2_0
64
using System.Runtime.Intrinsics.X86;
75
#endif
8-
using System.Text;
9-
using System.Threading;
10-
using BitFaster.Caching.Lfu;
116

127
namespace BitFaster.Caching.Buffers
138
{
@@ -17,7 +12,7 @@ namespace BitFaster.Caching.Buffers
1712
/// rehashed to select a different buffer to retry up to 3 times. Using this approach
1813
/// writes scale linearly with number of concurrent threads.
1914
/// </summary>
20-
public class StripedMpmcBuffer<T>
15+
public sealed class StripedMpmcBuffer<T>
2116
{
2217
const int MaxAttempts = 3;
2318

BitFaster.Caching/Buffers/StripedMpscBuffer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.Linq;
5-
using System.Text;
6-
using System.Threading;
74

85
#if !NETSTANDARD2_0
96
using System.Runtime.Intrinsics.X86;
@@ -18,7 +15,7 @@ namespace BitFaster.Caching.Buffers
1815
/// writes scale linearly with number of concurrent threads.
1916
/// </summary>
2017
[DebuggerDisplay("Count = {Count}/{Capacity}")]
21-
public class StripedMpscBuffer<T> where T : class
18+
public sealed class StripedMpscBuffer<T> where T : class
2219
{
2320
const int MaxAttempts = 3;
2421

BitFaster.Caching/Lfu/CmSketch.cs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
/*
2-
* Copyright 2015 Ben Manes. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
using System;
1+
using System;
182
using System.Collections.Generic;
19-
using System.Text;
203

214
namespace BitFaster.Caching.Lfu
225
{
23-
// https://en.wikipedia.org/wiki/Count%E2%80%93min_sketch#:~:text=In%20computing%2C%20the%20count%E2%80%93min,some%20events%20due%20to%20collisions.
24-
// Parallel count min: https://www.atlantis-press.com/proceedings/mmebc-16/25859036
25-
// SIMD: https://thlujy.github.io/papers/Lujianyuan-tpds-ufbf.pdf
26-
// https://github.com/ben-manes/caffeine/blob/master/caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java
27-
// https://github.com/ben-manes/caffeine/blob/master/caffeine/src/test/java/com/github/benmanes/caffeine/cache/FrequencySketchTest.java
28-
public class CmSketch<T>
6+
/// <summary>
7+
/// A probabilistic data structure used to estimate the frequency of a given value. Periodic aging reduces the
8+
/// accumulated count across all values over time, such that a historic popular value will decay to zero frequency
9+
/// over time if it is not accessed.
10+
/// </summary>
11+
/// <remarks>
12+
/// This is a direct C# translation of FrequencySketch in the Caffeine library by ben.manes@gmail.com (Ben Manes).
13+
/// http://www.apache.org/licenses/LICENSE-2.0
14+
/// </remarks>
15+
public sealed class CmSketch<T>
2916
{
3017
// A mixture of seeds from FNV-1a, CityHash, and Murmur3
3118
private static ulong[] Seed = { 0xc3a5c85c97cb3127L, 0xb492b66fbe98f273L, 0x9ae16a3b2f90404fL, 0xcbf29ce484222325L};

BitFaster.Caching/Lfu/LfuCapacityPartition.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Text;
53

64
namespace BitFaster.Caching.Lfu
75
{
86
[DebuggerDisplay("{Capacity} ({Window}/{Protected}/{Probation})")]
9-
public class LfuCapacityPartition
7+
public sealed class LfuCapacityPartition
108
{
119
private readonly int max;
1210

BitFaster.Caching/Lfu/LfuNodeList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BitFaster.Caching.Lfu
1010
/// Adapted from the .NET linked list code, but with arg checking only applied in debug builds.
1111
/// </summary>
1212
[DebuggerDisplay("Count = {Count}")]
13-
internal class LfuNodeList<K, V> : IEnumerable<LfuNode<K, V>>
13+
internal sealed class LfuNodeList<K, V> : IEnumerable<LfuNode<K, V>>
1414
{
1515
internal LfuNode<K, V> head;
1616
private int count;

BitFaster.Caching/Scheduler/ForegroundScheduler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
using System.Threading.Tasks;
52

63
namespace BitFaster.Caching.Scheduler
74
{
85
/// <summary>
96
/// Represents a scheduler that runs tasks synchronously.
107
/// </summary>
11-
public class ForegroundScheduler : IScheduler
8+
public sealed class ForegroundScheduler : IScheduler
129
{
1310
private long count;
1411

BitFaster.Caching/Scheduler/NullScheduler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace BitFaster.Caching.Scheduler
88
/// <summary>
99
/// Represents a scheduler that does no scheduling. Scheduled Tasks will not be run.
1010
/// </summary>
11-
public class NullScheduler : IScheduler
11+
public sealed class NullScheduler : IScheduler
1212
{
1313
private long count;
1414

BitFaster.Caching/Scheduler/ThreadPoolScheduler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace BitFaster.Caching.Scheduler
99
/// <summary>
1010
/// Represents a scheduler that handles queuing tasks to execute in the ThreadPool.
1111
/// </summary>
12-
public class ThreadPoolScheduler : IScheduler
12+
public sealed class ThreadPoolScheduler : IScheduler
1313
{
1414
private long count;
1515
private Optional<Exception> lastException = Optional<Exception>.None();

0 commit comments

Comments
 (0)