?? versionedstorage.cs
字號:
{
keywords.Add(keyword);
}
}
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, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
db.Merge(occurences), kind, timestamp));
}
break;
}
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, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.numPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp));
}
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, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.timePropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp));
}
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, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.strPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp));
}
}
if (val is string)
{
string str = (string)prop.val;
int wc = str.IndexOf('*');
if (wc < 0)
{
Key key = new Key(new object[]{def, str});
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.strPropIndex.GetEnumerator(key, key), kind, timestamp));
}
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, type, uri, wc == str.Length-1 ? restOfPatterns : patterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.strPropIndex.GetEnumerator(fromKey, tillKey), kind, timestamp));
}
}
else if (val is double)
{
Key key = new Key(new object[]{def, val});
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.numPropIndex.GetEnumerator(key, key), kind, timestamp));
}
else if (val is DateTime)
{
Key key = new Key(new object[]{def, (DateTime)val});
return new SearchResult(root, type, uri, restOfPatterns, kind, timestamp,
new ReferenceIterator(root, (PropDef[])refs.ToArray(typeof(PropDef)),
root.timePropIndex.GetEnumerator(key, key), kind, timestamp));
}
else if (val is NameVal)
{
return SearchReferenceProperty(type, uri, patterns, kind, timestamp, (NameVal)val, compound, def, refs);
}
else if (val is NameVal[])
{
NameVal[] props = (NameVal[])val;
if (props.Length > 0)
{
return SearchReferenceProperty(type, uri, patterns, kind, timestamp, props[0], true, def, refs);
}
}
return null;
}
/// <summary>Close database</summary>
public void Close()
{
db.Close();
}
/// <summary>Commit current transaction</summary>
public void Commit()
{
db.Commit();
root.Unlock();
}
/// <summary>Rollback current transaction</summary>
public void Rollback()
{
db.Rollback();
root.Unlock();
}
/// <summary>
/// Begin new write transction: set exclusive lock
/// </summary>
public void BeginTransaction()
{
root.ExclusiveLock();
}
class SearchResult:IEnumerable,IEnumerator
{
VersionHistory type;
string uri;
NameVal[] patterns;
SearchKind kind;
DateTime timestamp;
IEnumerator iterator;
Thing currThing;
int currVersion;
Link currHistory;
DatabaseRoot root;
public IEnumerator GetEnumerator()
{
return this;
}
public SearchResult(DatabaseRoot root, VersionHistory type, string uri, NameVal[] patterns, SearchKind kind, DateTime timestamp, IEnumerator iterator)
{
this.root = root;
this.type = type;
this.uri = uri;
this.patterns = patterns;
this.kind = kind;
this.timestamp = timestamp;
this.iterator = iterator;
}
public void Reset()
{
iterator.Reset();
currThing = null;
currHistory = null;
}
public bool MoveNext()
{
currThing = null;
Repeat:
if (currHistory != null)
{
while (currVersion < currHistory.Count)
{
Thing thing = (Thing)currHistory[currVersion++];
if (Match(thing))
{
return true;
}
}
currHistory = null;
}
while (iterator.MoveNext())
{
object curr = iterator.Current;
if (curr is Thing)
{
if (Match((Thing)curr))
{
return true;
}
}
else if (curr is VersionHistory)
{
currHistory = ((VersionHistory)curr).versions;
currVersion = 0;
goto Repeat;
}
}
return false;
}
private static bool MatchString(string str, string pat)
{
if (pat.IndexOf('*') < 0)
{
return pat.Equals(str);
}
int pi = 0, si = 0, pn = pat.Length, sn = str.Length;
int wildcard = -1, strpos = -1;
while (true)
{
if (pi < pn && pat[pi] == '*')
{
wildcard = ++pi;
strpos = si;
}
else if (si == sn)
{
return pi == pn;
}
else if (pi < pn && str[si] == pat[pi])
{
si += 1;
pi += 1;
}
else if (wildcard >= 0)
{
si = ++strpos;
pi = wildcard;
}
else
{
return false;
}
}
}
private bool Match(Thing thing)
{
if (type != null && !thing.IsInstanceOf(type, kind, timestamp))
{
return false;
}
switch (kind)
{
case SearchKind.LatestVersion:
if (!thing.IsLatest())
{
return false;
}
break;
case SearchKind.LatestBefore:
if (thing.timestamp > timestamp || thing.vh.GetLatestBefore(timestamp) != thing)
{
return false;
}
break;
case SearchKind.OldestAfter:
if (thing.timestamp < timestamp || thing.vh.GetOldestAfter(timestamp) != thing)
{
return false;
}
break;
default:
break;
}
if (uri != null)
{
if (!MatchString(thing.vh.uri, uri))
{
return false;
}
}
for (int i = 0; i < patterns.Length; i++)
{
if (!MatchProperty(patterns[i], thing))
{
return false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -