?? versionedstorage.cs
字號:
}
}
IEnumerator[] occurences = new IEnumerator[keywords.Count];
for (int i = 0; i < occurences.Length; i++)
{
Key key = new Key((string)keywords[i]);
occurences[i] = root.inverseIndex.GetEnumerator(key, key);
}
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp, db.Merge(occurences));
}
break;
}
PropDef def = (PropDef)root.propDefIndex[prop.name];
if (def == null)
{
return new object[0]; // empty selection
}
if (val is Range)
{
Range range = (Range)val;
if (range.from is double)
{
Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive);
Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive);
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp,
root.numPropIndex.GetEnumerator(fromKey, tillKey));
}
else if (range.from is DateTime)
{
Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive);
Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive);
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp,
root.timePropIndex.GetEnumerator(fromKey, tillKey));
}
else
{
Key fromKey = new Key(new object[]{def, range.from}, range.fromInclusive);
Key tillKey = new Key(new object[]{def, range.till}, range.tillInclusive);
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp,
root.strPropIndex.GetEnumerator(fromKey, tillKey));
}
}
else if (val is string)
{
string str = (string)val;
int wc = str.IndexOf('*');
if (wc < 0)
{
Key key = new Key(new object[]{def, str});
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp,
root.strPropIndex.GetEnumerator(key, key));
}
else if (wc > 0)
{
string prefix = str.Substring(0, wc);
Key fromKey = new Key(new object[]{def, prefix});
Key tillKey = new Key(new object[]{def, prefix + Char.MaxValue}, false);
return new SearchResult(root, typeVh, uri, wc == str.Length-1 ? restOfPatterns : patterns, kind, timestamp,
root.strPropIndex.GetEnumerator(fromKey, tillKey));
}
}
else if (val is double)
{
Key key = new Key(new object[]{def, val});
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp,
root.numPropIndex.GetEnumerator(key, key));
}
else if (val is DateTime)
{
Key key = new Key(new object[]{def, val});
return new SearchResult(root, typeVh, uri, restOfPatterns, kind, timestamp,
root.timePropIndex.GetEnumerator(key, key));
}
else if (val is NameVal)
{
IEnumerable iterator = SearchReferenceProperty(typeVh, uri, patterns, kind, timestamp, (NameVal)val, false, def, new ArrayList());
if (iterator != null)
{
return iterator;
}
}
else if (val is NameVal[])
{
NameVal[] props = (NameVal[])val;
if (props.Length > 0)
{
IEnumerable iterator = SearchReferenceProperty(typeVh, uri, patterns, kind, timestamp, props[0], props.Length > 1, def, new ArrayList());
if (iterator != null)
{
return iterator;
}
}
}
}
if (kind == SearchKind.LatestVersion)
{
return new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.latest.GetEnumerator());
}
return new SearchResult(root, typeVh, uri, patterns, kind, timestamp, root.timeIndex.GetEnumerator());
}
finally
{
root.Unlock();
}
}
class ReferenceIterator:IEnumerable,IEnumerator
{
PropDef[] defs;
IEnumerator[] iterators;
int pos;
Thing currThing;
SearchKind kind;
DateTime timestamp;
DatabaseRoot root;
Hashtable visited;
public IEnumerator GetEnumerator()
{
return this;
}
public ReferenceIterator(DatabaseRoot root, PropDef[] defs, IEnumerator iterator, SearchKind kind, DateTime timestamp)
{
this.root = root;
this.defs = defs;
this.kind = kind;
this.timestamp = timestamp;
iterators = new IEnumerator[defs.Length+1];
iterators[iterators.Length-1] = iterator;
Reset();
}
public void Reset()
{
visited = new Hashtable();
currThing = null;
pos = iterators.Length-1;
iterators[pos].Reset();
}
public object Current
{
get
{
if (currThing == null)
{
throw new InvalidOperationException("No current element");
}
return currThing;
}
}
public bool MoveNext()
{
while (true)
{
while (pos < iterators.Length && !iterators[pos].MoveNext())
{
pos += 1;
}
if (pos == iterators.Length)
{
currThing = null;
return false;
}
Thing thing = (Thing)iterators[pos].Current;
switch (kind)
{
case SearchKind.LatestVersion:
if (!thing.IsLatest())
{
continue;
}
break;
case SearchKind.LatestBefore:
if (thing.timestamp > timestamp)
{
continue;
}
break;
case SearchKind.OldestAfter:
if (thing.timestamp < timestamp)
{
continue;
}
break;
}
if (pos == 0)
{
if (visited.ContainsKey(thing.Oid))
{
continue;
}
else
{
visited[thing.Oid] = true;
}
currThing = thing;
return true;
}
pos -= 1;
Key key = new Key(new object[]{defs[pos], thing.vh});
iterators[pos] = root.refPropIndex.GetEnumerator(key, key);
}
}
}
private IEnumerable SearchReferenceProperty(VersionHistory type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp, NameVal prop, bool compound, PropDef def, ArrayList refs)
{
refs.Add(def);
NameVal[] restOfPatterns = compound ? patterns : SubArray(patterns);
object val = prop.val;
switch (prop.name)
{
case Symbols.Timestamp:
if (val is Range)
{
Range range = (Range)val;
if (range.from is DateTime)
{
Key fromKey = new Key((DateTime)range.from, range.fromInclusive);
Key tillKey = new Key((DateTime)range.till, range.tillInclusive);
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.timeIndex.GetEnumerator(fromKey, tillKey), kind, timestamp));
}
}
else if (val is DateTime)
{
Key key = new Key((DateTime)val);
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.timeIndex.GetEnumerator(key, key), kind, timestamp));
}
return new object[0]; // empty selection
case Symbols.Rectangle:
if (val is NameVal[])
{
NameVal[] coord = (NameVal[])val;
if (coord.Length == 4)
{
RectangleR2 r = new RectangleR2((double)coord[0].val,
(double)coord[1].val,
(double)coord[2].val,
(double)coord[3].val);
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.spatialIndex.Overlaps(r).GetEnumerator(), kind, timestamp));
}
}
break;
case Symbols.Point:
if (val is NameVal[])
{
NameVal[] coord = (NameVal[])val;
if (coord.Length == 2)
{
double x = (double)coord[0].val;
double y = (double)coord[1].val;
RectangleR2 r = new RectangleR2(x, y, x, y);
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.spatialIndex.Overlaps(r).GetEnumerator(), kind, timestamp));
}
}
break;
case Symbols.Keyword:
if (val is string)
{
ArrayList keywords = new ArrayList();
foreach (string keyword in ((string)val).ToLower().Split(keywordSeparators))
{
if (keyword.Length > 0 && !keywordStopList.ContainsKey(keyword))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -