optimizing-fast-lookup

Solid

Implements fast O(1) lookup patterns using HashSet, FrozenSet, and optimized Dictionary in .NET. Use when building high-performance search or membership testing operations.

Testing & QA 40 stars 6 forks Updated 6 days ago MIT

Install

View on GitHub

Quality Score: 78/100

Stars 20%
54
Recency 20%
100
Frontmatter 20%
40
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# .NET Fast Lookup A guide for fast lookup APIs leveraging O(1) time complexity. **Quick Reference:** See [QUICKREF.md](QUICKREF.md) for essential patterns at a glance. ## 1. Core APIs | API | Time Complexity | Features | |-----|-----------------|----------| | `HashSet<T>` | O(1) | Mutable, no duplicates | | `FrozenSet<T>` | O(1) | Immutable, .NET 8+ | | `Dictionary<K,V>` | O(1) | Mutable, Key-Value | | `FrozenDictionary<K,V>` | O(1) | Immutable, .NET 8+ | --- ## 2. HashSet<T> ```csharp // O(1) time complexity for existence check var allowedIds = new HashSet<int> { 1, 2, 3, 4, 5 }; if (allowedIds.Contains(userId)) { // Allowed user } // Set operations setA.IntersectWith(setB); // Intersection setA.UnionWith(setB); // Union setA.ExceptWith(setB); // Difference ``` --- ## 3. FrozenSet<T> (.NET 8+) ```csharp using System.Collections.Frozen; // Immutable fast lookup (read-only scenarios) var allowedExtensions = new[] { ".jpg", ".png", ".gif" } .ToFrozenSet(StringComparer.OrdinalIgnoreCase); if (allowedExtensions.Contains(fileExtension)) { // Allowed extension } ``` --- ## 4. Dictionary<K,V> Optimization ```csharp // ❌ Two lookups if (dict.ContainsKey(key)) { var value = dict[key]; } // ✅ Single lookup if (dict.TryGetValue(key, out var value)) { // Use value } // Lookup with default value var value = dict.GetValueOrDefault(key, defaultValue); ``` --- ## 5. Comparer Optimization ```csharp // Case-insensitive string comparison var set...

Details

Author
christian289
Repository
christian289/dotnet-with-claudecode
Created
7 months ago
Last Updated
6 days ago
Language
C#
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category