Skip to content

Instantly share code, notes, and snippets.

@mjs3339
mjs3339 / BoyerMooreString.cs
Created March 7, 2022 11:25
BoyerMoore String Searching Algorithm
using System;
using System.Collections.Generic;
public class BoyerMooreString
{
private const int CMaxValue = char.MaxValue;
private int[] _jumpTable;
private string _pattern;
private int _patternLength;
public BoyerMooreString()
@mjs3339
mjs3339 / BoyerMooreGeneric.cs
Last active March 13, 2022 13:37
C# Boyer Moore Generic Search Algorithm
using System;
using System.Collections.Generic;
public class BoyerMooreGeneric<T>
{
private readonly IEqualityComparer<T> _comparer;
private Dictionary<T, int> _jumpTable;
private T[] _pattern;
private int _patternLength;
public BoyerMooreGeneric()
{
@mjs3339
mjs3339 / MSet15.cs
Created July 27, 2021 10:24
Internal Mini HashSet version 15
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
[DebuggerDisplay("Count = {" + nameof(Count) + "}")]
[Serializable]
public class MSet15<T>
{
private int[] _hashBuckets;
internal IEqualityComparer<T> Comparer;
@mjs3339
mjs3339 / CcDictionary.cs
Created July 27, 2021 10:21
Concurrent Dictionary Class without Blocking
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
[DebuggerDisplay("Count = {" + nameof(Count) + "}")]
public class CcDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
{
private readonly int _size;
@mjs3339
mjs3339 / ObjectIndexer4.cs
Created January 12, 2021 14:27
Sequential Ordering Object Indexer
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
[DebuggerDisplay("Count = {" + nameof(Count) + "}")]
[Serializable]
public class ObjectIndexer4 : IEnumerable<object>
{
private readonly FNV1a32 hasher;
@mjs3339
mjs3339 / LinqHelper.cs
Created January 12, 2021 14:24
Custom Linq Range Class
using System;
using System.Collections.Generic;
using System.Numerics;
public static class LinqHelper
{
/// <summary>
/// Generates a sequence of character values within a specified range starting at
/// 'form' through 'to' with a given step value.
/// </summary>
public static IEnumerable<char> Range(char from, char to, char step = '\x0001')
@mjs3339
mjs3339 / SHA3ModInt.cs
Created January 12, 2021 14:21
Modified Sha3
using System;
[Serializable]
public class SHA3ModInt : HashAlgorithmEx
{
private readonly KeccakSpongeManaged _sponge;
public SHA3ModInt(int size, int rounds = 24, ulong[] seed = null)
{
if (rounds > 24)
throw new Exception($"Maximum rounds allowed is {24}");
var MaxBR = (64 >> 3) * 25;
@mjs3339
mjs3339 / JitterCacheRng.cs
Created January 12, 2021 14:19
Jitter Cache
using System;
using System.Security.Cryptography;
using System.Threading;
[Serializable]
public class JitterCacheRng : RandomNumberGenerator
{
private const int ReSecureThreshold = 10;
private readonly SHA3ModInt _algorithm;
private readonly JitterEx _jit;
private readonly int _moveSize;
@mjs3339
mjs3339 / ConcurrencyCheck.cs
Created January 12, 2021 14:16
Check and Store Concurrency Usage
using System;
using System.Diagnostics;
using System.Threading;
public class ConcurrencyCheck
{
public volatile ConcurrencyInfo ConcurrencyInformation = new ConcurrencyInfo();
private static int ProcessorCount => Environment.ProcessorCount;
public bool OverrideAutoConcurrency
{
get;
@mjs3339
mjs3339 / BigDecimal.cs
Last active August 27, 2021 19:10
Arbitrary Precision Signed BigDecimal
using System;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
[Serializable]
[DebuggerDisplay("{DDisplay}")]
public struct BigDecimal : IComparable, IComparable<BigDecimal>, IEquatable<BigDecimal>
{
private const int MaxFactorials = 200;