private void WithDatabase(string file, IFunction4 function) { Configure(); IExtObjectContainer objectContainer = Db4oFactory.OpenFile(file).Ext(); try { function.Apply(objectContainer); } finally { objectContainer.Close(); } IObjectServer server = Db4oFactory.OpenServer(ClientServerFileName(file), -1); server.GrantAccess(Username, Password); objectContainer = Db4oFactory.OpenClient("localhost", server.Ext().Port(), Username , Password).Ext(); try { function.Apply(objectContainer); } finally { objectContainer.Close(); server.Close(); } }
private bool ForEachConstraintRecursively(IFunction4 block) { IQueue4 queue = new NoDuplicatesQueue(new NonblockingQueue()); IEnumerator constrIter = IterateConstraints(); while (constrIter.MoveNext()) { queue.Add(constrIter.Current); } while (queue.HasNext()) { QCon constr = (QCon)queue.Next(); bool cancel = (bool)block.Apply(constr); if (cancel) { return(true); } IEnumerator childIter = constr.IterateChildren(); while (childIter.MoveNext()) { queue.Add(childIter.Current); } IEnumerator joinIter = constr.IterateJoins(); while (joinIter.MoveNext()) { queue.Add(joinIter.Current); } } return(false); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { if (key == null) { throw new ArgumentNullException(); } if (_am.Remove(key)) { _am.AddFirst(key); return _slots[key]; } if (_a1.Remove(key)) { _am.AddFirst(key); return _slots[key]; } if (_slots.Count >= _maxSize) { DiscardPage(finalizer); } object value = producer.Apply(key); _slots[key] = value; _a1.AddFirst(key); return value; }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { object value = _slots[key]; if (value == null) { object newValue = producer.Apply(key); if (newValue == null) { return null; } if (_slots.Count >= _maxSize) { object discarded = Sharpen.Collections.Remove(_slots, _lru.RemoveLast()); if (null != finalizer) { finalizer.Apply(discarded); } } _slots[key] = newValue; _lru.AddFirst(key); return newValue; } _lru.Remove(key); // O(N) _lru.AddFirst(key); return value; }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { if (key == null) { throw new ArgumentNullException(); } if (_am.Remove(key)) { _am.AddFirst(key); return(_slots[key]); } if (_a1.Remove(key)) { _am.AddFirst(key); return(_slots[key]); } if (_slots.Count >= _maxSize) { DiscardPage(finalizer); } object value = producer.Apply(key); _slots[key] = value; _a1.AddFirst(key); return(value); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { object value = _slots[key]; if (value == null) { object newValue = producer.Apply(key); if (newValue == null) { return(null); } if (_slots.Count >= _maxSize) { object discarded = Sharpen.Collections.Remove(_slots, _lru.RemoveLast()); if (null != finalizer) { finalizer.Apply(discarded); } } _slots[key] = newValue; _lru.AddFirst(key); return(newValue); } _lru.Remove(key); // O(N) _lru.AddFirst(key); return(value); }
private object AsTopLevelCall(IFunction4 block, Transaction trans) { trans = CheckTransaction(trans); BeginTopLevelCall(); try { return(block.Apply(trans)); } catch (Db4oRecoverableException exc) { throw; } catch (SystemException exc) { throw; } catch (Exception exc) { FatalShutdown(exc); } finally { EndTopLevelCall(); } // should never happen - just to make compiler happy throw new Db4oException(); }
public virtual int NewId() { AdjustIdGenerator(_idGenerator); if (!_overflow) { return(_idGenerator); } int id = (((int)_findFreeId.Apply(_idGenerator))); if (id > 0) { AdjustIdGenerator(id - 1); return(id); } id = (((int)_findFreeId.Apply(_minValidId))); if (id > 0) { AdjustIdGenerator(id - 1); return(id); } throw new Db4oFatalException("Out of IDs"); }
private static object WithContainer(string filename, IFunction4 block) { IObjectContainer container = Db4oFactory.OpenFile(filename); try { return(block.Apply(container)); } finally { container.Close(); } }
private void ReclaimFor(object key, IFunction4 producer, IProcedure4 finalizer) { if (_slots.Count < _maxSize) { _slots[key] = producer.Apply(key); return; } if (_a1in.Size() > _inSize) { var lastKey = _a1in.RemoveLast(); Discard(lastKey, finalizer); if (_a1out.IsFull()) { _a1out.RemoveLast(); } _a1out.AddFirst(lastKey); } else { var lastKey = _am.RemoveLast(); Discard(lastKey, finalizer); } _slots[key] = producer.Apply(key); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { if (_am.Remove((((long)key)))) { _am.AddFirst((((long)key))); return _slots[((long)key)]; } if (_a1.Remove((((long)key)))) { _am.AddFirst((((long)key))); return _slots[((long)key)]; } if (_slots.Count >= _maxSize) { DiscardPage(finalizer); } object value = producer.Apply(((long)key)); _slots[((long)key)] = value; _a1.AddFirst((((long)key))); return value; }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { if (_am.Remove((((long)key)))) { _am.AddFirst((((long)key))); return(_slots[((long)key)]); } if (_a1.Remove((((long)key)))) { _am.AddFirst((((long)key))); return(_slots[((long)key)]); } if (_slots.Count >= _maxSize) { DiscardPage(finalizer); } var value = producer.Apply(((long)key)); _slots[((long)key)] = value; _a1.AddFirst((((long)key))); return(value); }
private void ReclaimFor(object key, IFunction4 producer, IProcedure4 finalizer) { if (_slots.Count < _maxSize) { _slots[key] = producer.Apply(key); return; } if (_a1in.Size() > _inSize) { object lastKey = _a1in.RemoveLast(); Discard(lastKey, finalizer); if (_a1out.IsFull()) { _a1out.RemoveLast(); } _a1out.AddFirst(lastKey); } else { object lastKey = _am.RemoveLast(); Discard(lastKey, finalizer); } _slots[key] = producer.Apply(key); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { long longKey = (((long)key)); if (_last == null) { object lastValue = producer.Apply(((long)key)); if (lastValue == null) { return null; } _size = 1; LRULongCache.Entry lastEntry = new LRULongCache.Entry(longKey, lastValue); _slots.Put(longKey, lastEntry); _first = lastEntry; _last = lastEntry; return lastValue; } LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Get(longKey); if (entry == null) { if (_size >= _maxSize) { LRULongCache.Entry oldEntry = (LRULongCache.Entry)_slots.Remove(_last._key); _last = oldEntry._previous; _last._next = null; if (null != finalizer) { finalizer.Apply((object)oldEntry._value); } _size--; } object newValue = producer.Apply(((long)key)); if (newValue == null) { return null; } _size++; LRULongCache.Entry newEntry = new LRULongCache.Entry(longKey, newValue); _slots.Put(longKey, newEntry); _first._previous = newEntry; newEntry._next = _first; _first = newEntry; return newValue; } if (_first == entry) { return ((object)entry._value); } LRULongCache.Entry previous = entry._previous; entry._previous = null; if (_last == entry) { _last = previous; } previous._next = entry._next; if (previous._next != null) { previous._next._previous = previous; } _first._previous = entry; entry._next = _first; _first = entry; return ((object)entry._value); }
public object Produce(object key, IFunction4 producer, IProcedure4 onDiscard) { Record("Produce", key); return(producer.Apply(key)); }
public object Apply(object arg) { _enclosing._misses++; return(producer.Apply(arg)); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard ) { return(producer.Apply(key)); }
public virtual ITest Transmogrify(IFunction4 fun) { return ((ITest)fun.Apply(this)); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { long longKey = (((long)key)); if (_last == null) { object lastValue = producer.Apply(((long)key)); if (lastValue == null) { return(null); } _size = 1; LRULongCache.Entry lastEntry = new LRULongCache.Entry(longKey, lastValue); _slots.Put(longKey, lastEntry); _first = lastEntry; _last = lastEntry; return(lastValue); } LRULongCache.Entry entry = (LRULongCache.Entry)_slots.Get(longKey); if (entry == null) { if (_size >= _maxSize) { LRULongCache.Entry oldEntry = (LRULongCache.Entry)_slots.Remove(_last._key); _last = oldEntry._previous; _last._next = null; if (null != finalizer) { finalizer.Apply((object)oldEntry._value); } _size--; } object newValue = producer.Apply(((long)key)); if (newValue == null) { return(null); } _size++; LRULongCache.Entry newEntry = new LRULongCache.Entry(longKey, newValue); _slots.Put(longKey, newEntry); _first._previous = newEntry; newEntry._next = _first; _first = newEntry; return(newValue); } if (_first == entry) { return((object)entry._value); } LRULongCache.Entry previous = entry._previous; entry._previous = null; if (_last == entry) { _last = previous; } previous._next = entry._next; if (previous._next != null) { previous._next._previous = previous; } _first._previous = entry; entry._next = _first; _first = entry; return((object)entry._value); }
public object Produce(object key, IFunction4 producer, IProcedure4 onDiscard) { Record("Produce", key); return producer.Apply(key); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { var intKey = (((int)key)); if (_last == null) { var lastValue = producer.Apply(((int)key)); if (lastValue == null) { return(null); } _size = 1; var lastEntry = new Entry(intKey, lastValue); _slots.Put(intKey, lastEntry); _first = lastEntry; _last = lastEntry; return(lastValue); } var entry = (Entry)_slots.Get(intKey); if (entry == null) { if (_size >= _maxSize) { var oldEntry = (Entry)_slots.Remove(_last._key); _last = oldEntry._previous; _last._next = null; if (null != finalizer) { finalizer.Apply(oldEntry._value); } _size--; } var newValue = producer.Apply(((int)key)); if (newValue == null) { return(null); } _size++; var newEntry = new Entry(intKey, newValue); _slots.Put(intKey, newEntry); _first._previous = newEntry; newEntry._next = _first; _first = newEntry; return(newValue); } if (_first == entry) { return(entry._value); } var previous = entry._previous; entry._previous = null; if (_last == entry) { _last = previous; } previous._next = entry._next; if (previous._next != null) { previous._next._previous = previous; } _first._previous = entry; entry._next = _first; _first = entry; return(entry._value); }
protected override object Map(object current) { return(_function.Apply(current)); }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 finalizer ) { var intKey = (((int) key)); if (_last == null) { var lastValue = producer.Apply(((int) key)); if (lastValue == null) { return null; } _size = 1; var lastEntry = new Entry(intKey, lastValue); _slots.Put(intKey, lastEntry); _first = lastEntry; _last = lastEntry; return lastValue; } var entry = (Entry) _slots.Get(intKey); if (entry == null) { if (_size >= _maxSize) { var oldEntry = (Entry) _slots.Remove(_last._key); _last = oldEntry._previous; _last._next = null; if (null != finalizer) { finalizer.Apply(oldEntry._value); } _size--; } var newValue = producer.Apply(((int) key)); if (newValue == null) { return null; } _size++; var newEntry = new Entry(intKey, newValue); _slots.Put(intKey, newEntry); _first._previous = newEntry; newEntry._next = _first; _first = newEntry; return newValue; } if (_first == entry) { return entry._value; } var previous = entry._previous; entry._previous = null; if (_last == entry) { _last = previous; } previous._next = entry._next; if (previous._next != null) { previous._next._previous = previous; } _first._previous = entry; entry._next = _first; _first = entry; return entry._value; }
private bool ForEachConstraintRecursively(IFunction4 block) { IQueue4 queue = new NoDuplicatesQueue(new NonblockingQueue()); var constrIter = IterateConstraints(); while (constrIter.MoveNext()) { queue.Add(constrIter.Current); } while (queue.HasNext()) { var constr = (QCon) queue.Next(); var cancel = (bool) block.Apply(constr); if (cancel) { return true; } var childIter = constr.IterateChildren(); while (childIter.MoveNext()) { queue.Add(childIter.Current); } var joinIter = constr.IterateJoins(); while (joinIter.MoveNext()) { queue.Add(joinIter.Current); } } return false; }
public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard ) { return producer.Apply(key); }
public object Apply(object test) { return((ITest)fun.Apply(((ITest)test))); }
private static object WithContainer(string filename, IFunction4 block) { var container = Db4oFactory.OpenFile(filename); try { return block.Apply(container); } finally { container.Close(); } }
public ITest Transmogrify(IFunction4 fun) { return (ITest) fun.Apply(this); }
public virtual ITest Transmogrify(IFunction4 fun) { return((ITest)fun.Apply(this)); }
public bool MoveNext() { Current = function.Apply(Current); return(true); }