コード例 #1
0
ファイル: SozuTable.cs プロジェクト: tshhaha/Terab
        public void Write(TxoPack txos, SectorIndex sectorIndex, Hash256 sectorHash)
        {
            if (_config.ImplicitSectors)
            {
                throw new InvalidOperationException();
            }

            var partition = PartitionByExplicitSector(sectorIndex, sectorHash, txos.GetForwardIterator());

            Write(partition, txos);
        }
コード例 #2
0
ファイル: SozuTable.cs プロジェクト: tshhaha/Terab
        /// <summary>
        /// Reading layers with explicit outpoint ranges.
        /// </summary>
        /// <param name="txoIn">txopack providing outpoints requesting a read</param>
        /// <param name="sectorIndex">Identifies the first sector to be read.</param>
        /// <param name="sectorHash">Identifies the hash range of the sector.</param>
        /// <param name="txoOut">output txoPack to collect read results</param>
        private void Read(TxoPack txoIn, SectorIndex sectorIndex, Hash256 sectorHash, TxoPack txoOut)
        {
            if (_config.ImplicitSectors)
            {
                throw new InvalidOperationException();
            }

            var partition = PartitionByExplicitSector(sectorIndex, sectorHash, txoIn.GetForwardIterator());

            Read(partition, txoOut);
        }
コード例 #3
0
ファイル: SozuTable.cs プロジェクト: tshhaha/Terab
        /// <param name="start">Context provided by the upper layer.</param>
        /// <param name="leftTxid">Context provided by the upper layer.</param>
        /// <param name="iter">Should be sorted in increasing order.</param>
        private IEnumerable <SectorRange> PartitionByExplicitSector(
            SectorIndex start,
            Hash256 leftTxid,
            TxoForwardIterator iter)
        {
            var localSectorTxoPackWriteAnchor = _rangeOutputs.GetResetWriter();

            var localSectorHash = leftTxid;

            // TODO: [vermorel] To be replaced by a regular 'foreach'
            for (; iter.EndNotReached; iter.MoveNext())
            {
                var outpoint      = iter.Current;
                var canonicalHash = outpoint.Txid.Truncate(_config.SectorBitDepth);

                Debug.Assert(localSectorHash.CompareTo(canonicalHash) <= 0, "Unordered outpoints.");

                if (!canonicalHash.Equals(localSectorHash))
                {
                    // reach here means current outpoint from iterator is in different sector than
                    // localSectorHash, thus we need to flush what were written so far in writer
                    if (!localSectorTxoPackWriteAnchor.IsEmpty)
                    {
                        // this works because subSectors are all allocated once
                        var rangeIndex = start.GetNext(localSectorHash.Top(_config.SectorBitDepth) -
                                                       leftTxid.Top(_config.SectorBitDepth));
                        yield return(new SectorRange(rangeIndex, localSectorHash, _rangeOutputs));

                        // recycling the list
                        localSectorTxoPackWriteAnchor = _rangeOutputs.GetResetWriter();
                    }

                    // flush done, we switch to next leftTxid
                    localSectorHash = canonicalHash;
                }

                localSectorTxoPackWriteAnchor.Write(in outpoint, ReadOnlySpan <byte> .Empty);
            }

            if (!localSectorTxoPackWriteAnchor.IsEmpty)
            {
                var rangeIndex = start.GetNext(localSectorHash.Top(_config.SectorBitDepth) -
                                               leftTxid.Top(_config.SectorBitDepth));
                yield return(new SectorRange(rangeIndex, localSectorHash, _rangeOutputs));
            }
        }
コード例 #4
0
ファイル: SozuTable.cs プロジェクト: tshhaha/Terab
 public SectorRange(SectorIndex index, Hash256 leftTxid, TxoPack outpoints)
 {
     Index     = index;
     LeftTxid  = leftTxid;
     Outpoints = outpoints;
 }