本文整理汇总了C#中Slice.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Slice.CopyTo方法的具体用法?C# Slice.CopyTo怎么用?C# Slice.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slice
的用法示例。
在下文中一共展示了Slice.CopyTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritePrefix
public void WritePrefix(Slice prefix, int prefixId)
{
var prefixNodeSize = Constants.PrefixNodeHeaderSize + prefix.Size;
prefixNodeSize += prefixNodeSize & 1;
var prefixNodeOffset = (ushort)(Upper - prefixNodeSize);
Upper = prefixNodeOffset;
Debug.Assert(_prefixSection->NextPrefixId == prefixId);
if (_prefixSection->PrefixOffsets[prefixId] != 0)
throw new InvalidOperationException(string.Format("Cannot write a prefix '{0}' at the following offset position: {1} because it's already taken by another prefix. The offset for the prefix {1} is {2}. ", prefix, prefixId, _prefixSection->PrefixOffsets[prefixId]));
_prefixSection->PrefixOffsets[prefixId] = prefixNodeOffset;
var prefixNodeHeader = (PrefixNodeHeader*)(_base + prefixNodeOffset);
prefixNodeHeader->PrefixLength = prefix.Size;
prefix.CopyTo((byte*)prefixNodeHeader + Constants.PrefixNodeHeaderSize);
_prefixSection->NextPrefixId++;
}
示例2: Add
public void Add(Transaction tx, Slice key, Slice value, ushort? version = null)
{
if (value == null) throw new ArgumentNullException("value");
State.IsModified = true;
var pos = DirectAdd(tx, key, value.Size, version: version);
value.CopyTo(pos);
}
示例3: CreateNode
private NodeHeader* CreateNode(int index, Slice key, NodeFlags flags, int len, ushort previousNodeVersion)
{
Debug.Assert(index <= NumberOfEntries && index >= 0);
Debug.Assert(IsBranch == false || index != 0 || key.Size == 0);// branch page's first item must be the implicit ref
if (HasSpaceFor(key, len) == false)
throw new InvalidOperationException("The page is full and cannot add an entry, this is probably a bug");
// move higher pointers up one slot
for (int i = NumberOfEntries; i > index; i--)
{
KeysOffsets[i] = KeysOffsets[i - 1];
}
var nodeSize = SizeOf.NodeEntry(PageMaxSpace, key, len);
var node = AllocateNewNode(index, key, nodeSize, previousNodeVersion);
if (key.Options == SliceOptions.Key)
key.CopyTo((byte*)node + Constants.NodeHeaderSize);
node->Flags = flags;
return node;
}
示例4: MultiAdd
public void MultiAdd(Transaction tx, Slice key, Slice value, ushort? version = null)
{
if (value == null) throw new ArgumentNullException("value");
if (value.Size > tx.DataPager.MaxNodeSize)
throw new ArgumentException(
"Cannot add a value to child tree that is over " + tx.DataPager.MaxNodeSize + " bytes in size", "value");
if (value.Size == 0)
throw new ArgumentException("Cannot add empty value to child tree");
State.IsModified = true;
Lazy<Cursor> lazy;
var page = FindPageFor(tx, key, out lazy);
if (page == null || page.LastMatch != 0)
{
var ptr = DirectAdd(tx, key, value.Size, version: version);
value.CopyTo(ptr);
return;
}
page = tx.ModifyPage(page.PageNumber, page);
var item = page.GetNode(page.LastSearchPosition);
CheckConcurrency(key, version, item->Version, TreeActionType.Add);
var existingValue = new Slice(DirectRead(tx, key), (ushort) item->DataSize);
if (existingValue.Compare(value, _cmp) == 0)
return; //nothing to do, the exact value is already there
if (item->Flags == NodeFlags.MultiValuePageRef)
{
var tree = OpenOrCreateMultiValueTree(tx, key, item);
tree.DirectAdd(tx, value, 0);
}
else // need to turn to tree
{
var tree = Create(tx, _cmp, TreeFlags.MultiValue);
var current = NodeHeader.GetData(tx, item);
tree.DirectAdd(tx, current, 0);
tree.DirectAdd(tx, value, 0);
tx.AddMultiValueTree(this, key, tree);
// we need to record that we switched to tree mode here, so the next call wouldn't also try to create the tree again
DirectAdd(tx, key, sizeof (TreeRootHeader), NodeFlags.MultiValuePageRef);
}
}
示例5: TestSlice
public void TestSlice()
{
BufferAllocator<float> bufferAllocator = new BufferAllocator<float>(FloatNumSlices * 2048, 1, sizeof(float));
Buf<float> buffer = bufferAllocator.Allocate();
Slice<Sample, float> slice = new Slice<Sample, float>(buffer, 0, FloatNumSlices, FloatSliverSize);
HoloDebug.Assert(slice.Duration == FloatNumSlices);
HoloDebug.Assert(slice.IsEmpty() == false);
HoloDebug.Assert(slice.SliverSize == FloatSliverSize);
var halfDuration = (FloatNumSlices / 2);
Slice<Sample, float> prefixSlice = slice.Subslice(0, halfDuration);
Slice<Sample, float> prefixSlice2 = slice.SubsliceOfDuration(halfDuration);
Slice<Sample, float> suffixSlice = slice.Subslice(halfDuration, halfDuration);
Slice<Sample, float> suffixSlice2 = slice.SubsliceStartingAt(halfDuration);
HoloDebug.Assert(prefixSlice.Precedes(suffixSlice));
HoloDebug.Assert(prefixSlice.Precedes(suffixSlice2));
HoloDebug.Assert(prefixSlice2.Precedes(suffixSlice));
HoloDebug.Assert(prefixSlice2.Precedes(suffixSlice2));
PopulateFloatSlice(slice);
Buf<float> buffer2 = bufferAllocator.Allocate();
Slice<Sample, float> slice2 = new Slice<Sample, float>(buffer2, 0, FloatNumSlices, FloatSliverSize);
slice.CopyTo(slice2);
VerifySlice(slice2);
}