コード例 #1
0
        public (HashNode <T> previous, HashNode <T> current) GetNodeByKey(string key)
        {
            int          position = GetBucketByKey(key);
            HashNode <T> listNode = buckets[position];
            HashNode <T> previous = null;

            while (null != listNode)
            {
                if (listNode.Key == key)
                {
                    return(previous, listNode);
                }
                previous = listNode;
                listNode = listNode.Next;
            }
            return(null, null);
        }
コード例 #2
0
        public T GetNode(string key)
        {
            if (key != "-1")
            {
                ValidateKey(key);

                var(_, node) = GetNodeByKey(key);



                return(node.Value);
            }
            var valueNode = new HashNode <T> {
                Key = key, Next = null
            };



            return(valueNode.Value);
        }
コード例 #3
0
        public void Add(string key, T item)
        {
            ValidateKey(key);

            var valueNode = new HashNode <T> {
                Key = key, Value = item, Next = null
            };
            int position = GetBucketByKey(key);

            listNode = buckets[position];

            if (null == listNode)
            {
                buckets[position] = valueNode;
            }
            else
            {
                while (null != listNode.Next)
                {
                    listNode = listNode.Next;
                }
                listNode.Next = valueNode;
            }
        }