?? thickindex.cs
字號:
public virtual IDictionaryEnumerator GetDictionaryEnumerator()
{
return new ExtendDictionaryEnumerator(index.GetDictionaryEnumerator());
}
#if USE_GENERICS
public override IEnumerator<V> GetEnumerator()
{
return new ExtendEnumerator(((IEnumerable<IPersistent>)index).GetEnumerator());
}
#else
public override IEnumerator GetEnumerator()
{
return new ExtendEnumerator(index.GetEnumerator());
}
#endif
#if USE_GENERICS
public IEnumerator<V> GetEnumerator(Key from, Key till, IterationOrder order)
#else
public IEnumerator GetEnumerator(Key from, Key till, IterationOrder order)
#endif
{
return Range(from, till, order).GetEnumerator();
}
#if USE_GENERICS
public IEnumerator<V> GetEnumerator(K from, K till, IterationOrder order)
#else
public IEnumerator GetEnumerator(object from, object till, IterationOrder order)
#endif
{
return Range(from, till, order).GetEnumerator();
}
#if USE_GENERICS
public IEnumerator<V> GetEnumerator(Key from, Key till)
#else
public IEnumerator GetEnumerator(Key from, Key till)
#endif
{
return Range(from, till).GetEnumerator();
}
#if USE_GENERICS
public IEnumerator<V> GetEnumerator(K from, K till)
#else
public IEnumerator GetEnumerator(object from, object till)
#endif
{
return Range(from, till).GetEnumerator();
}
#if USE_GENERICS
public IEnumerator<V> GetEnumerator(string prefix)
#else
public IEnumerator GetEnumerator(string prefix)
#endif
{
return StartsWith(prefix).GetEnumerator();
}
#if USE_GENERICS
public virtual IEnumerable<V> Range(Key from, Key till, IterationOrder order)
#else
public virtual IEnumerable Range(Key from, Key till, IterationOrder order)
#endif
{
return new ExtendEnumerator(index.GetEnumerator(from, till, order));
}
#if USE_GENERICS
public virtual IEnumerable<V> Reverse()
#else
public virtual IEnumerable Reverse()
#endif
{
return new ExtendEnumerator(index.Reverse().GetEnumerator());
}
#if USE_GENERICS
public virtual IEnumerable<V> Range(Key from, Key till)
#else
public virtual IEnumerable Range(Key from, Key till)
#endif
{
return new ExtendEnumerator(index.GetEnumerator(from, till));
}
#if USE_GENERICS
public IEnumerable<V> Range(K from, K till, IterationOrder order)
#else
public IEnumerable Range(object from, object till, IterationOrder order)
#endif
{
return new ExtendEnumerator(index.GetEnumerator(from, till, order));
}
#if USE_GENERICS
public IEnumerable<V> Range(K from, K till)
#else
public IEnumerable Range(object from, object till)
#endif
{
return new ExtendEnumerator(index.GetEnumerator(from, till));
}
#if USE_GENERICS
public IEnumerable<V> StartsWith(string prefix)
#else
public IEnumerable StartsWith(string prefix)
#endif
{
return new ExtendEnumerator(index.GetEnumerator(prefix));
}
public virtual IDictionaryEnumerator GetDictionaryEnumerator(Key from, Key till, IterationOrder order)
{
return new ExtendDictionaryEnumerator(index.GetDictionaryEnumerator(from, till, order));
}
public Type KeyType
{
get
{
return index.KeyType;
}
}
#if USE_GENERICS
public bool Put(Key key, V obj)
{
IPersistent s = index.Get(key);
if (s == null)
{
Relation<V,V> r = Storage.CreateRelation<V,V>(null);
r.Add(obj);
index.Put(key, r);
}
else if (s is Relation<V,V>)
{
Relation<V,V> r = (Relation<V,V>)s;
if (r.Count == BTREE_THRESHOLD)
{
ISet<V> ps = Storage.CreateSet<V>();
for (int i = 0; i < BTREE_THRESHOLD; i++)
{
ps.Add(r[i]);
}
ps.Add(obj);
index.Set(key, ps);
r.Deallocate();
}
else
{
r.Add(obj);
}
}
else
{
((ISet<V>)s).Add(obj);
}
nElems += 1;
Modify();
return true;
}
#else
public bool Put(Key key, IPersistent obj)
{
IPersistent s = index.Get(key);
if (s == null)
{
Relation r = Storage.CreateRelation(null);
r.Add(obj);
index.Put(key, r);
}
else if (s is Relation)
{
Relation r = (Relation)s;
if (r.Count == BTREE_THRESHOLD)
{
ISet ps = Storage.CreateSet();
for (int i = 0; i < BTREE_THRESHOLD; i++)
{
ps.Add(r.GetRaw(i));
}
ps.Add(obj);
index.Set(key, ps);
r.Deallocate();
}
else
{
r.Add(obj);
}
}
else
{
((ISet)s).Add(obj);
}
nElems += 1;
Modify();
return true;
}
#endif
#if USE_GENERICS
public V Set(Key key, V obj)
{
IPersistent s = index.Get(key);
if (s == null)
{
Relation<V,V> r = Storage.CreateRelation<V,V>(null);
r.Add(obj);
index.Put(key, r);
nElems += 1;
Modify();
return null;
}
else if (s is Relation<V,V>)
{
Relation<V,V> r = (Relation<V,V>)s;
if (r.Count == 1)
{
V prev = r[0];
r[0] = obj;
return prev;
}
}
throw new StorageError(StorageError.ErrorCode.KEY_NOT_UNIQUE);
}
#else
public IPersistent Set(Key key, IPersistent obj)
{
IPersistent s = index.Get(key);
if (s == null)
{
Relation r = Storage.CreateRelation(null);
r.Add(obj);
index[key] = r;
nElems += 1;
Modify();
return null;
}
else if (s is Relation)
{
Relation r = (Relation)s;
if (r.Count == 1)
{
IPersistent prev = r[0];
r[0] = obj;
return prev;
}
}
throw new StorageError(StorageError.ErrorCode.KEY_NOT_UNIQUE);
}
#endif
#if USE_GENERICS
public void Remove(Key key, V obj)
{
IPersistent s = index.Get(key);
if (s is Relation<V,V>)
{
Relation<V,V> r = (Relation<V,V>)s;
int i = r.IndexOf(obj);
if (i >= 0)
{
r.Remove(i);
if (r.Count == 0)
{
index.Remove(key, r);
r.Deallocate();
}
nElems -= 1;
Modify();
return;
}
}
else if (s is ISet<V>)
{
ISet<V> ps = (ISet<V>)s;
if (ps.Remove(obj))
{
if (ps.Count == 0)
{
index.Remove(key, ps);
ps.Deallocate();
}
nElems -= 1;
Modify();
return;
}
}
throw new StorageError(StorageError.ErrorCode.KEY_NOT_FOUND);
}
#else
public void Remove(Key key, IPersistent obj)
{
IPersistent s = index[key];
if (s is Relation)
{
Relation r = (Relation)s;
int i = r.IndexOf(obj);
if (i >= 0)
{
r.Remove(i);
if (r.Count == 0)
{
index.Remove(key, r);
r.Deallocate();
}
nElems -= 1;
Modify();
return;
}
}
else if (s is ISet)
{
ISet ps = (ISet)s;
if (ps.Remove(obj))
{
if (ps.Count == 0)
{
index.Remove(key, ps);
ps.Deallocate();
}
nElems -= 1;
Modify();
return;
}
}
throw new StorageError(StorageError.ErrorCode.KEY_NOT_FOUND);
}
#endif
#if USE_GENERICS
public V Remove(Key key)
#else
public IPersistent Remove(Key key)
#endif
{
throw new StorageError(StorageError.ErrorCode.KEY_NOT_UNIQUE);
}
#if USE_GENERICS
public bool Put(K key, V obj)
#else
public bool Put(object key, IPersistent obj)
#endif
{
return Put(KeyBuilder.getKeyFromObject(key), obj);
}
#if USE_GENERICS
public V Set(K key, V obj)
#else
public IPersistent Set(object key, IPersistent obj)
#endif
{
return Set(KeyBuilder.getKeyFromObject(key), obj);
}
#if USE_GENERICS
public void Remove(K key, V obj)
#else
public void Remove(object key, IPersistent obj)
#endif
{
Remove(KeyBuilder.getKeyFromObject(key), obj);
}
#if USE_GENERICS
public V RemoveKey(K key)
#else
public IPersistent Remove(object key)
#endif
{
throw new StorageError(StorageError.ErrorCode.KEY_NOT_UNIQUE);
}
public override void Deallocate()
{
Clear();
index.Deallocate();
base.Deallocate();
}
#if USE_GENERICS
public V GetAt(int i)
#else
public object GetAt(int i)
#endif
{
IDictionaryEnumerator e;
if (i < 0 || i >= nElems)
{
throw new IndexOutOfRangeException("Position " + i + ", index size " + nElems);
}
if (i <= (nElems/2))
{
e = GetDictionaryEnumerator(null, null, IterationOrder.AscentOrder);
while (i-- >= 0)
{
e.MoveNext();
}
}
else
{
e = GetDictionaryEnumerator(null, null, IterationOrder.DescentOrder);
i -= nElems;
while (++i < 0)
{
e.MoveNext();
}
}
#if USE_GENERICS
return (V)e.Value;
#else
return e.Value;
#endif
}
public IDictionaryEnumerator GetDictionaryEnumerator(int start, IterationOrder order)
{
return new ExtendDictionaryStartFromEnumerator(this, start, order);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -