Exemplo n.º 1
0
 internal ImMapTree(ImMapData <V> data, ImMap <V> left, ImMap <V> right, int height)
 {
     Data       = data;
     Left       = left;
     Right      = right;
     TreeHeight = height;
 }
Exemplo n.º 2
0
 private void AvlTreeAction(Type key)
 {
     if (imMap.GetValueOrDefault(key) is null)
     {
         imMap = imMap.AddOrUpdate(key, null);
     }
 }
Exemplo n.º 3
0
        public static State UpdateRadioButtons(ImMap <string, int> radioButtons, State state)
        {
            var uiState = GetUIState(state);

            uiState.RadioButtons = radioButtons;
            return(UpdateUIState(uiState, state));
        }
Exemplo n.º 4
0
        public static bool TryFind <V>(this ImMap <V> map, int key, out V value)
        {
            int mapKey;

            while (map is ImMapTree <V> mapTree)
            {
                mapKey = mapTree.Data.Key;
                if (key < mapKey)
                {
                    map = mapTree.Left;
                }
                else if (key > mapKey)
                {
                    map = mapTree.Right;
                }
                else
                {
                    value = mapTree.Data.Value;
                    return(true);
                }
            }

            if (map is ImMapData <V> leaf && leaf.Key == key)
            {
                value = leaf.Value;
                return(true);
            }

            value = default;
            return(false);
        }
Exemplo n.º 5
0
 internal ImMapTree(ImMapData <V> data, ImMapTree <V> left, ImMapTree <V> right)
 {
     Data       = data;
     Left       = left;
     Right      = right;
     TreeHeight = left.TreeHeight > right.TreeHeight ? left.TreeHeight + 1 : right.TreeHeight + 1;
 }
Exemplo n.º 6
0
 internal ImMapTree(ImMapData <V> data, ImMapData <V> leftData, ImMapData <V> rightData)
 {
     Data       = data;
     Left       = leftData;
     Right      = rightData;
     TreeHeight = 2;
 }
Exemplo n.º 7
0
 public static V GetValueOrDefault <V>(this ImMap <V> map, int key, V defaultValue)
 {
     while (map.Height != 0 && map.Key != key)
     {
         map = key < map.Key ? map.Left : map.Right;
     }
     return(map.Height != 0 ? map.Value : defaultValue);
 }
Exemplo n.º 8
0
 public static V GetValueOrDefault <V>(this ImMap <V> map, int key)
 {
     while (map.Height != 0 && map.Key != key)
     {
         map = key < map.Key ? map.Left : map.Right;
     }
     return(map.Value); // that's fine to return the value without check, because for we have a default value in empty map
 }
Exemplo n.º 9
0
        internal ImMapTree(ImMapData <V> data, ImMap <V> left, int rightHeight, ImMap <V> right)
        {
            Data  = data;
            Left  = left;
            Right = right;
            var leftHeight = left.Height;

            TreeHeight = leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
        }
Exemplo n.º 10
0
 public void Setup()
 {
     lock (dictionaryWithLock)
     {
         foreach (var type in Classes.Types)
         {
             dictionary[type]           = new object();
             dictionaryWithLock[type]   = new object();
             concurrentDictionary[type] = new object();
             hashArrayMap.AddIfNotExist(type, new object());
             imMap = imMap.AddOrUpdate(type, new object());
         }
     }
 }
Exemplo n.º 11
0
        public static ImMap <V> AddOrUpdate <V>(this ImMap <V> map, int key, V value)
        {
            if (map is ImMapTree <V> tree)
            {
                return(key == tree.Data.Key
                    ? new ImMapTree <V>(new ImMapData <V>(key, value), tree.Left, tree.Right, tree.TreeHeight)
                    : tree.AddOrUpdateLeftOrRight(key, value));
            }

            if (map is ImMapBranch <V> treeLeaf)
            {
                if (key > treeLeaf.Data.Key)
                {
                    return(treeLeaf.IsLeftOriented
                        ? new ImMapTree <V>(treeLeaf.Data, treeLeaf.LeftOrRight, new ImMapData <V>(key, value))
                        : key <treeLeaf.LeftOrRight.Key  // rotate if right
                               ?new ImMapTree <V>(new ImMapData <V>(key, value), treeLeaf.Data, treeLeaf.LeftOrRight)
                               : key> treeLeaf.LeftOrRight.Key
                            ? new ImMapTree <V>(treeLeaf.LeftOrRight, treeLeaf.Data, new ImMapData <V>(key, value))
                        : (ImMap <V>) new ImMapBranch <V>(treeLeaf.Data, new ImMapData <V>(key, value)));
                }

                if (key < treeLeaf.Data.Key)
                {
                    return(treeLeaf.IsRightOriented
                        ? new ImMapTree <V>(treeLeaf.Data, new ImMapData <V>(key, value), treeLeaf.LeftOrRight)
                        : key > treeLeaf.LeftOrRight.Key // rotate if left
                            ? new ImMapTree <V>(new ImMapData <V>(key, value), treeLeaf.LeftOrRight, treeLeaf.Data)
                        : key < treeLeaf.LeftOrRight.Key
                            ? new ImMapTree <V>(treeLeaf.LeftOrRight, new ImMapData <V>(key, value), treeLeaf.Data)
                        : (ImMap <V>) new ImMapBranch <V>(treeLeaf.Data, new ImMapData <V>(key, value)));
                }

                return(new ImMapBranch <V>(new ImMapData <V>(key, value), treeLeaf.LeftOrRight));
            }

            if (map is ImMapData <V> data)
            {
                return(key > data.Key
                    ? new ImMapBranch <V>(data, new ImMapData <V>(key, value))
                : key < data.Key
                    ? new ImMapBranch <V>(new ImMapData <V>(key, value), data)
                : (ImMap <V>) new ImMapData <V>(key, value));
            }

            return(new ImMapData <V>(key, value));
        }
Exemplo n.º 12
0
        public static bool TryFind <V>(this ImMap <V> map, int key, out V value)
        {
            while (map.Height != 0)
            {
                if (key < map.Key)
                {
                    map = map.Left;
                }
                else if (key > map.Key)
                {
                    map = map.Right;
                }
                else
                {
                    break;
                }
            }

            value = map.Value;
            return(map.Height != 0);
        }
Exemplo n.º 13
0
        public BenchmarkTest()
        {
            NErrorLog.Enabled = true;
            NatashaInitializer.InitializeAndPreheating();
            model            = new TestModel();
            _imMap           = ImMap <string> .Empty;
            _imHashMap       = ImHashMap <string, string> .Empty;
            FuzzyHandler     = model.Model1.FuzzyTree();
            HashHandler      = model.Model1.HashTree();
            PrecisionHandler = model.Model1.PrecisioTree();
            DictHandler      = model.Model1;
            Dictionary <int, string> hashDict = new();

            foreach (var item in model.Model1)
            {
                _imHashMap = _imHashMap.AddOrUpdate(item.Key, item.Value);
                _imMap     = _imMap.AddOrUpdate(Int32.Parse(item.Key), item.Value);
                hashDict[Int32.Parse(item.Key)] = item.Value;
            }
            HashCodePrecisionHandler = hashDict.CustomerTree(item => item.ToString());
            ConDictHandler           = new ConcurrentDictionary <string, string>(model.Model1);
            ReadonlyDictHandler      = ImmutableDictionary.CreateRange(DictHandler);
        }
Exemplo n.º 14
0
 public UIState(List <PopupType> popups, ImMap <string, int> radioButtons)
 {
     Popups       = popups;
     RadioButtons = radioButtons;
 }