本文整理汇总了C#中IFunction4.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# IFunction4.Apply方法的具体用法?C# IFunction4.Apply怎么用?C# IFunction4.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFunction4
的用法示例。
在下文中一共展示了IFunction4.Apply方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Produce
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;
}
示例2: Produce
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;
}
示例3: Produce
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;
}
示例4: ReclaimFor
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);
}
示例5: Produce
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);
}
示例6: Transmogrify
public virtual ITest Transmogrify(IFunction4 fun)
{
return ((ITest)fun.Apply(this));
}
示例7: WithDatabase
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();
}
}
示例8: Produce
public object Produce(object key, IFunction4 producer, IProcedure4 onDiscard)
{
Record("Produce", key);
return producer.Apply(key);
}
示例9: Transmogrify
public ITest Transmogrify(IFunction4 fun)
{
return (ITest) fun.Apply(this);
}
示例10: WithContainer
private static object WithContainer(string filename, IFunction4 block)
{
var container = Db4oFactory.OpenFile(filename);
try
{
return block.Apply(container);
}
finally
{
container.Close();
}
}
示例11: Produce
public virtual object Produce(object key, IFunction4 producer, IProcedure4 onDiscard
)
{
return producer.Apply(key);
}
示例12: ForEachConstraintRecursively
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;
}
示例13: Produce
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;
}