Exemple #1
0
        public IList <T> Find(params IComparable[] startFields)
        {
            if (startFields.Length > _fields.Length)
            {
                throw new InvalidOperationException("Too many search field");
            }

            IComparable[] values = new IComparable[_fields.Length];
            for (int i = 0; i < startFields.Length; i++)
            {
                values[i] = startFields[i];
            }

            List <T> list = new List <T>();

            if (_indexEntrys.Count == 0)
            {
                return(list);
            }

            IICIndexObject startObject = new IICIndexObject(values, 0);

            using (IICLockRegion region = _innerLock.LockForRead()) {
                int start = SearchFirstItem(startObject);
                if (start < 0)
                {
                    return(list);
                }

                if (!_indexEntrys.Keys[start].StartsWith(startObject))
                {
                    start++;
                }

                for (int i = start; i < _indexEntrys.Count && _indexEntrys.Keys[i].StartsWith(startObject); i++)
                {
                    list.Add(_indexEntrys.Values[i]);
                }
            }
            return(list);
        }
Exemple #2
0
        public V Search(K key, out int index)
        {
            if (_searchEntrys.Count == 0)
            {
                index = -1;
                return(default(V));
            }

            using (IICLockRegion region = _lockSegs.LockForRead()) {
                int begin = 0;
                int end   = _searchEntrys.Count - 1;

                KeyValueObject seg;
                while (end - begin > 1)
                {
                    int middle = (end + begin) / 2;
                    seg = _searchEntrys.Values[middle];
                    int compareResult = seg.beginKey.CompareTo(key);

                    if (compareResult == 0)
                    {
                        index = middle;
                        return(seg.obj);
                    }
                    else
                    {
                        if (key.CompareTo(seg.beginKey) > 0)
                        {
                            begin = middle;
                        }
                        else
                        {
                            end = middle;
                        }
                    }
                }

                if (end == begin)
                {
                    index = begin;
                    seg   = _searchEntrys.Values[begin];
                    if (key.CompareTo(seg.beginKey) >= 0 && key.CompareTo(seg.endKey) <= 0)
                    {
                        return(seg.obj);
                    }
                }
                else
                {
                    seg = _searchEntrys.Values[begin];
                    if (key.CompareTo(seg.beginKey) >= 0 && key.CompareTo(seg.endKey) <= 0)
                    {
                        index = begin;
                        return(seg.obj);
                    }

                    seg = _searchEntrys.Values[end];
                    if (key.CompareTo(seg.beginKey) >= 0 && key.CompareTo(seg.endKey) <= 0)
                    {
                        index = end;
                        return(seg.obj);
                    }
                }
            }

            index = -1;
            return(default(V));
        }
Exemple #3
0
 public int IndexOf(T item)
 {
     using (IICLockRegion region = _innerLock.LockForRead()) {
         return(_innerList.IndexOf(item));
     }
 }
Exemple #4
0
 public bool ContainsKey(K key)
 {
     using (IICLockRegion region = _innerLock.LockForRead()) {
         return(_innerDic.ContainsKey(key));
     }
 }