// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma warning disable 1591
using System;
namespace FASTER.core
{
///
/// Default empty functions base class to make it easy for users to provide
/// their own implementation
///
///
///
///
///
///
public abstract class FunctionsBase : IFunctions
{
public virtual void ConcurrentReader(ref Key key, ref Input input, ref Value value, ref Output dst) { }
public virtual void SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst) { }
public virtual bool ConcurrentWriter(ref Key key, ref Value src, ref Value dst) { dst = src; return true; }
public virtual void SingleWriter(ref Key key, ref Value src, ref Value dst) => dst = src;
public virtual void InitialUpdater(ref Key key, ref Input input, ref Value value) { }
public virtual void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue) { }
public virtual bool InPlaceUpdater(ref Key key, ref Input input, ref Value value) { return true; }
public virtual void ReadCompletionCallback(ref Key key, ref Input input, ref Output output, Context ctx, Status status) { }
public virtual void RMWCompletionCallback(ref Key key, ref Input input, Context ctx, Status status) { }
public virtual void UpsertCompletionCallback(ref Key key, ref Value value, Context ctx) { }
public virtual void DeleteCompletionCallback(ref Key key, Context ctx) { }
public virtual void CheckpointCompletionCallback(Guid sessionId, long serialNum) { }
}
///
/// Default empty functions base class to make it easy for users to provide
/// their own implementation
///
///
///
///
public class SimpleFunctions : FunctionsBase
{
private readonly Func merger;
public SimpleFunctions() => merger = (l, r) => l;
public SimpleFunctions(Func merger) => this.merger = merger;
public override void ConcurrentReader(ref Key key, ref Value input, ref Value value, ref Value dst) => dst = value;
public override void SingleReader(ref Key key, ref Value input, ref Value value, ref Value dst) => dst = value;
public override bool ConcurrentWriter(ref Key key, ref Value src, ref Value dst) { dst = src; return true; }
public override void SingleWriter(ref Key key, ref Value src, ref Value dst) => dst = src;
public override void InitialUpdater(ref Key key, ref Value input, ref Value value) => value = input;
public override void CopyUpdater(ref Key key, ref Value input, ref Value oldValue, ref Value newValue) => newValue = merger(input, oldValue);
public override bool InPlaceUpdater(ref Key key, ref Value input, ref Value value) { value = merger(input, value); return true; }
public override void ReadCompletionCallback(ref Key key, ref Value input, ref Value output, Context ctx, Status status) { }
public override void RMWCompletionCallback(ref Key key, ref Value input, Context ctx, Status status) { }
public override void UpsertCompletionCallback(ref Key key, ref Value value, Context ctx) { }
public override void DeleteCompletionCallback(ref Key key, Context ctx) { }
public override void CheckpointCompletionCallback(Guid sessionId, long serialNum) { }
}
public class SimpleFunctions : SimpleFunctions
{
public SimpleFunctions() : base() { }
public SimpleFunctions(Func merger) : base(merger) { }
}
}