本文整理汇总了C#中Slice类的典型用法代码示例。如果您正苦于以下问题:C# Slice类的具体用法?C# Slice怎么用?C# Slice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Slice类属于命名空间,在下文中一共展示了Slice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEmptySliceAtMid
public void TestEmptySliceAtMid()
{
Slice<int> x = new Slice<int>(new[] { 1, 2, 3, 4 });
x = x.Slc(1, 1);
Assert.IsEmpty(x.ToArray());
}
示例2: Contains
public bool Contains(string treeName, Slice key, out ushort? version, WriteBatch writeBatch = null)
{
if (writeBatch != null)
{
WriteBatch.BatchOperationType operationType;
Stream stream;
if (writeBatch.TryGetValue(treeName, key, out stream, out version, out operationType))
{
switch (operationType)
{
case WriteBatch.BatchOperationType.Add:
return true;
case WriteBatch.BatchOperationType.Delete:
return false;
default:
throw new ArgumentOutOfRangeException(operationType.ToString());
}
}
}
var tree = GetTree(treeName);
var readVersion = tree.ReadVersion(key);
var exists = readVersion > 0;
version = exists ? (ushort?)readVersion : null;
return exists;
}
示例3: TestCreateOverArray
public bool TestCreateOverArray(Tester t)
{
for (int i = 0; i < 2; i++) {
var ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// Try out two ways of creating a slice:
Slice<int> slice;
if (i == 0) {
slice = new Slice<int>(ints);
}
else {
slice = ints.Slice();
}
t.AssertEqual(ints.Length, slice.Length);
// Now try out two ways of walking the slice's contents:
for (int j = 0; j < ints.Length; j++) {
t.AssertEqual(ints[j], slice[j]);
}
{
int j = 0;
foreach (var x in slice) {
t.AssertEqual(ints[j], x);
j++;
}
}
}
return true;
}
示例4: FindShortestSeparator
public override void FindShortestSeparator(ref string start, Slice limit)
{
// Find length of common prefix
int minLength = Math.Min(start.Length, limit.Size);
int diffIndex = 0;
while ((diffIndex < minLength) && (start[diffIndex].Equals((char)limit[diffIndex])))
{
diffIndex++;
}
if (diffIndex >= minLength)
{
// Do not shorten if one string is a prefix of the other
}
else
{
byte diffByte = (byte)start[diffIndex];
if (diffByte < 0xff &&
diffByte + 1 < limit[diffIndex])
{
start = start.Set(diffIndex,(char) (start[diffIndex] + 1));
start = start.Resize(diffIndex + 1);
Debug.Assert(Compare(new Slice(start), limit) < 0);
}
}
}
示例5: FdbWatch
internal FdbWatch(FdbFuture<Slice> future, Slice key, Slice value)
{
Contract.Requires(future != null);
m_future = future;
m_key = key;
m_value = value;
}
示例6: Status
private Status(CodeEnum code, Slice msg, Slice msg2)
{
Debug.Assert(code != CodeEnum.kOk);
int len1 = msg.Size;
int len2 = 0;
if (msg2 != null)
{
len2 = msg2.Size;
}
int size = len1 + (len2 != 0 ? (2 + len2) : 0);
byte[] result = new byte[size + 5];
Buffer.BlockCopy(BitConverter.GetBytes(size), 0, result, 0, 4);
result[4] = (byte) Code;
msg.Data.CopyTo(result,5, len1);
if (len2!=0)
{
result[5 + len1] = (byte)':';
result[6 + len1] = (byte)' ';
msg2.Data.CopyTo(result, 7 + len1, len2);
}
m_state = result;
}
示例7: OnData
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
// MARKET ORDERS
MarketOrders();
// LIMIT ORDERS
LimitOrders();
// STOP MARKET ORDERS
StopMarketOrders();
// STOP LIMIT ORDERS
StopLimitOrders();
// MARKET ON OPEN ORDERS
MarketOnOpenOrders();
// MARKET ON CLOSE ORDERS
MarketOnCloseOrders();
}
示例8: CreateOrOpenAsync
/// <summary>Opens the directory with the given <paramref name="path"/>.
/// If the directory does not exist, it is created (creating parent directories if necessary).
/// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
/// </summary>
public static Task<FdbDirectorySubspace> CreateOrOpenAsync(this IFdbDirectory directory, IFdbTransactional db, IEnumerable<string> path, Slice layer, CancellationToken cancellationToken)
{
if (directory == null) throw new ArgumentNullException("directory");
if (db == null) throw new ArgumentNullException("db");
if (path == null) throw new ArgumentNullException("path");
return db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), cancellationToken);
}
示例9: Seek
public bool Seek(Slice key)
{
if (this.ValidateCurrentKey(Current, _cmp) == false)
return false;
CurrentKey = NodeHeader.GetData(_tx, _item);
return true;
}
示例10: DecodeFrom
public Status DecodeFrom(ref Slice input)
{
ByteArrayPointer magicPtr = input.Data + (kEncodedLength - 8);
UInt32 magicLo = Coding.DecodeFixed32(magicPtr);
UInt32 magicHi = Coding.DecodeFixed32(magicPtr + 4);
UInt64 magic = (((UInt64)(magicHi) << 32) | ((UInt64)(magicLo)));
if (magic != FormatHelper.kTableMagicNumber)
{
return Status.InvalidArgument("not an sstable (bad magic number)");
}
Status result = MetaindexHandle.DecodeFrom(ref input);
if (result.IsOk)
{
result = IndexHandle.DecodeFrom(ref input);
}
if (result.IsOk)
{
// We skip over any leftover data (just padding for now) in "input"
ByteArrayPointer end = magicPtr + 8;
input = new Slice(end, input.Data + input.Size - end);
}
return result;
}
示例11: ActivityEntry
public ActivityEntry(DebugActionType actionType, Slice key, string treeName, object value)
{
ActionType = actionType;
Key = key;
TreeName = treeName;
Value = value;
}
示例12: Store
private unsafe USlice Store(Slice data)
{
uint size = checked((uint)data.Count);
var buffer = m_keys.AllocateAligned(size);
UnmanagedHelpers.CopyUnsafe(buffer, data);
return new USlice(buffer, size);
}
示例13: TestEmptySliceAtZero
public void TestEmptySliceAtZero()
{
Slice<char> x = new Slice<char>("test!");
x = x.Slc(0, 0);
Assert.AreEqual("", x.ToString());
}
示例14: Indexing_ThrowsIfOutOfRange
public void Indexing_ThrowsIfOutOfRange()
{
var inner = new[] { 1, 2, 3, 4, 5 };
var subject = new Slice<int>(inner, 1, 2);
Check.ThatCode(() => subject[3]).Throws<IndexOutOfRangeException>();
}
示例15: Match
public bool Match(Slice slice)
{
MemoryAccess acc = slice.Expression as MemoryAccess;
if (acc == null)
return false;
b = acc.EffectiveAddress;
Constant offset = Constant.Create(b.DataType, 0);
BinaryOperator op = Operator.IAdd;
BinaryExpression ea = b as BinaryExpression;
if (ea != null)
{
Constant c= ea.Right as Constant;
if (c != null)
{
offset = c;
b = ea.Left;
}
}
else
{
b = acc.EffectiveAddress;
}
int bitBegin = slice.Offset;
int bitEnd = bitBegin + slice.DataType.BitSize;
if (0 <= bitBegin && bitEnd <= acc.DataType.BitSize)
{
offset = op.ApplyConstants(offset, Constant.Create(acc.EffectiveAddress.DataType, slice.Offset / 8));
b = new MemoryAccess(acc.MemoryId, new BinaryExpression(op, offset.DataType, b, offset), slice.DataType);
return true;
}
return false;
}