// /** // * File: MappingBTree.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using System.Runtime.CompilerServices; using System.Collections.Generic; using System.Collections; namespace ln.collections { public delegate K KeyMapping(V value); public class MappingBTree : IEnumerable { public KeyMapping KeyMapping { get; } private BTree tree; public MappingBTree(KeyMapping keyMapping) { KeyMapping = keyMapping; tree = new BTree(); } public MappingBTree(KeyMapping keyMapping,Comparison comparison) { KeyMapping = keyMapping; tree = new BTree(comparison); } public V this[K key] { get => tree[key]; set => tree[key] = value; } public void Clear() { tree.Clear(); } public int Count => tree.Count; public void Add(V v) => tree.Add(KeyMapping(v), v); public void TryAdd(V v) => tree.TryAdd(KeyMapping(v), v); public void Remove(V v) => tree.Remove(KeyMapping(v)); public bool TryRemove(V v) => tree.TryRemove(KeyMapping(v)); public bool TryGet(K key, out V v) => tree.TryGet(key, out v); public void RemoveKey(K key) => tree.Remove(key); public bool Contains(V v) => tree.ContainsKey(KeyMapping(v)); public bool ContainsKey(K k) => tree.ContainsKey(k); public IEnumerable Keys => tree.Keys; public IEnumerable Values => tree.Values; public V Next(V value) => tree[tree.Next(KeyMapping(value))]; public V Previous(V value) => tree[tree.Previous(KeyMapping(value))]; public IEnumerator GetEnumerator() => Values.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Values.GetEnumerator(); } }