From 489d1c818f98777bc3f582312ac39a40b0709432 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sat, 29 Aug 2015 21:16:49 +0300 Subject: [PATCH] TryGet, TryGetCurrent --- Novacoin/ByteQueue.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/Novacoin/ByteQueue.cs b/Novacoin/ByteQueue.cs index dc18437..9752c02 100644 --- a/Novacoin/ByteQueue.cs +++ b/Novacoin/ByteQueue.cs @@ -84,6 +84,18 @@ namespace Novacoin return _Elements[_Index++]; } + public bool TryGet(ref byte Element) + { + if (_Elements.Count <= _Index) + { + return false; + } + + Element = _Elements[_Index++]; + + return true; + } + public byte GetCurrent() { return _Elements[_Index]; @@ -99,6 +111,19 @@ namespace Novacoin return result; } + public bool TryGet(int nCount, ref byte[] Elements) + { + if (Count - Index < nCount) + { + return false; + } + + Elements = _Elements.GetRange(_Index, nCount).ToArray(); + _Index += nCount; + + return true; + } + public byte[] GetCurrent(int nCount) { Contract.Requires(Count - Index >= nCount, "nCount is greater than amount of elements."); @@ -108,6 +133,18 @@ namespace Novacoin return result; } + public bool TryGetCurrent(int nCount, ref byte[] Elements) + { + if (Count - Index < nCount) + { + return false; + } + + Elements = _Elements.GetRange(_Index, nCount).ToArray(); + + return true; + } + /// /// Current index value /// -- 1.7.1