Back to list
christian289

optimizing-fast-lookup

by christian289

ClaudeCode와 함께하는 .NET 개발 튜토리얼

1🍴 0📅 Jan 25, 2026

SKILL.md


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

.NET Fast Lookup

A guide for fast lookup APIs leveraging O(1) time complexity.

Quick Reference: See QUICKREF.md for essential patterns at a glance.

1. Core APIs

APITime ComplexityFeatures
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

// 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 (.NET 8+)

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

// ❌ 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

// Case-insensitive string comparison
var set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
set.Add("Hello");
set.Contains("HELLO"); // true

6. When to Use

ScenarioRecommended Collection
Frequently modified setHashSet<T>
Read-only configuration dataFrozenSet<T>
Frequent existence checksHashSet<T> / FrozenSet<T>
Key-Value cacheDictionary<K,V>
Static mapping tableFrozenDictionary<K,V>

7. References

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon