當前位置: 首頁>>代碼示例>>C#>>正文


C# Bits類代碼示例

本文整理匯總了C#中Bits的典型用法代碼示例。如果您正苦於以下問題:C# Bits類的具體用法?C# Bits怎麽用?C# Bits使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Bits類屬於命名空間,在下文中一共展示了Bits類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Parse

    public static StunMessage Parse(byte[] bytes)
    {
      var bits = new Bits(bytes);

      if (bits.Pop() != false || bits.Pop() != false)
      {
        throw new Exception("First two bits must be zeroes.");
      }

      var type = StunMessageType.Parse(bits.PopBits(14));

      var length = BitConverter.ToUInt16(bits.PopLittleEndianBytes(2), 0);

      var magicCookie = BitConverter.ToUInt32(bits.PopLittleEndianBytes(4), 0);
      if (magicCookie != MagicCookie)
      {
        throw new ArgumentException($"The parse magic cookie {magicCookie} doesn't match {MagicCookie}.", nameof(MagicCookie));
      }

      var attributes = new List<StunMessageAttribute>();
      for (var index = 0; index < length; index++)
      {
        attributes.Add(StunMessageAttribute.Parse(bits.PopBits(12 * 8)));
      }

      var id = StunMessageId.Parse(bits.PopLittleEndianBytes(12));

      return new StunMessage(type, attributes, id);
    }
開發者ID:Rhaeo,項目名稱:Rhaeo.Stun,代碼行數:29,代碼來源:StunMessage.cs

示例2: DoubleDocValuesAnonymousInnerClassHelper

 public DoubleDocValuesAnonymousInnerClassHelper(DoubleFieldSource outerInstance, DoubleFieldSource @this, FieldCache.Doubles arr, Bits valid)
     : base(@this)
 {
     this.outerInstance = outerInstance;
     this.arr = arr;
     this.valid = valid;
 }
開發者ID:paulirwin,項目名稱:lucene.net,代碼行數:7,代碼來源:DoubleFieldSource.cs

示例3: MultiBits

 public MultiBits(Bits[] subs, int[] starts, bool defaultValue)
 {
     Debug.Assert(starts.Length == 1 + subs.Length);
     this.Subs = subs;
     this.Starts = starts;
     this.DefaultValue = defaultValue;
 }
開發者ID:Cefa68000,項目名稱:lucenenet,代碼行數:7,代碼來源:MultiBits.cs

示例4: Parse

    public static StunMessageClass Parse(Bits bits)
    {
      if (bits.Count != 2)
      {
        throw new ArgumentException("The number of bits must be 2.", nameof(bits));
      }

      if (Request.Bits.SequenceEqual(bits.ToBitArray()))
      {
        return Request;
      }

      if (SuccessResponse.Bits.SequenceEqual(bits.ToBitArray()))
      {
        return SuccessResponse;
      }

      if (FailureResponse.Bits.SequenceEqual(bits.ToBitArray()))
      {
        return FailureResponse;
      }

      if (Indication.Bits.SequenceEqual(bits.ToBitArray()))
      {
        return Indication;
      }

      throw new InvalidOperationException("Invalid class.");
    }
開發者ID:Rhaeo,項目名稱:Rhaeo.Stun,代碼行數:29,代碼來源:StunMessageClass.cs

示例5: FloatDocValuesAnonymousInnerClassHelper

 public FloatDocValuesAnonymousInnerClassHelper(FloatFieldSource outerInstance, FloatFieldSource @this, FieldCache.Floats arr, Bits valid)
     : base(@this)
 {
     this.outerInstance = outerInstance;
     this.arr = arr;
     this.valid = valid;
 }
開發者ID:paulirwin,項目名稱:lucene.net,代碼行數:7,代碼來源:FloatFieldSource.cs

示例6: MatchAllScorer

 internal MatchAllScorer(MatchAllDocsQuery outerInstance, IndexReader reader, Bits liveDocs, Weight w, float score)
     : base(w)
 {
     this.OuterInstance = outerInstance;
     this.LiveDocs = liveDocs;
     this.Score_Renamed = score;
     MaxDoc = reader.MaxDoc;
 }
開發者ID:Cefa68000,項目名稱:lucenenet,代碼行數:8,代碼來源:MatchAllDocsQuery.cs

示例7: GetDocIdSet

 public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
 {
     if (processingMode == ProcessingMode.PM_FAST_INVALIDATION)
     {
         return FastBits(context.AtomicReader, acceptDocs);
     }
     else
     {
         return CorrectBits(context.AtomicReader, acceptDocs);
     }
 }
開發者ID:apache,項目名稱:lucenenet,代碼行數:11,代碼來源:DuplicateFilter.cs

示例8: Parse

    public static StunMessageMethod Parse(Bits bits)
    {
      if (bits.Count != 12)
      {
        throw new ArgumentException("The number of bits must be 12.", nameof(bits));
      }

      if (Binding.Bits.SequenceEqual(bits.ToBitArray()))
      {
        return Binding;
      }

      throw new InvalidOperationException("Invalid method.");
    }
開發者ID:Rhaeo,項目名稱:Rhaeo.Stun,代碼行數:14,代碼來源:StunMessageMethod.cs

示例9: GetDocIdSet

        public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
        {
            Terms terms = context.AtomicReader.Terms(term.Field());
            if (terms == null)
            {
                return null;
            }

            TermsEnum termsEnum = terms.Iterator(null);
            if (!termsEnum.SeekExact(term.Bytes()))
            {
                return null;
            }
            return new DocIdSetAnonymousInnerClassHelper(this, acceptDocs, termsEnum);
        }
開發者ID:paulirwin,項目名稱:lucene.net,代碼行數:15,代碼來源:TermFilter.cs

示例10: CorrectBits

        private FixedBitSet CorrectBits(AtomicReader reader, Bits acceptDocs)
        {
            FixedBitSet bits = new FixedBitSet(reader.MaxDoc); //assume all are INvalid
            Terms terms = reader.Fields.Terms(fieldName);

            if (terms == null)
            {
                return bits;
            }

            TermsEnum termsEnum = terms.Iterator(null);
            DocsEnum docs = null;
            while (true)
            {
                BytesRef currTerm = termsEnum.Next();
                if (currTerm == null)
                {
                    break;
                }
                else
                {
                    docs = termsEnum.Docs(acceptDocs, docs, DocsEnum.FLAG_NONE);
                    int doc = docs.NextDoc();
                    if (doc != DocIdSetIterator.NO_MORE_DOCS)
                    {
                        if (keepMode == KeepMode.KM_USE_FIRST_OCCURRENCE)
                        {
                            bits.Set(doc);
                        }
                        else
                        {
                            int lastDoc = doc;
                            while (true)
                            {
                                lastDoc = doc;
                                doc = docs.NextDoc();
                                if (doc == DocIdSetIterator.NO_MORE_DOCS)
                                {
                                    break;
                                }
                            }
                            bits.Set(lastDoc);
                        }
                    }
                }
            }
            return bits;
        }
開發者ID:apache,項目名稱:lucenenet,代碼行數:48,代碼來源:DuplicateFilter.cs

示例11: CheckTerms

        private void CheckTerms(Terms terms, Bits liveDocs, params string[] termsList)
        {
            Assert.IsNotNull(terms);
            TermsEnum te = terms.Iterator(null);

            foreach (string t in termsList)
            {
                BytesRef b = te.Next();
                Assert.IsNotNull(b);
                Assert.AreEqual(t, b.Utf8ToString());
                DocsEnum td = TestUtil.Docs(Random(), te, liveDocs, null, DocsEnum.FLAG_NONE);
                Assert.IsTrue(td.NextDoc() != DocIdSetIterator.NO_MORE_DOCS);
                Assert.AreEqual(0, td.DocID());
                Assert.AreEqual(td.NextDoc(), DocIdSetIterator.NO_MORE_DOCS);
            }
            Assert.IsNull(te.Next());
        }
開發者ID:joyanta,項目名稱:lucene.net,代碼行數:17,代碼來源:TestParallelTermEnum.cs

示例12: ToLittleEndianByteArray

    public byte[] ToLittleEndianByteArray()
    {
      var bits = new Bits(20);

      bits.AddOffBit();
      bits.AddOffBit();

      bits.AddBits(Type.Bits);

      var length = (ushort)(Attributes.Count() * 4 * 8);
      bits.AddUInt16LittleEndian(length);

      bits.AddUInt32LittleEndian(MagicCookie);

      bits.AddBytesLittleEndian(Id.Bytes);

      return bits.ToLittleEndianByteArray();
    }
開發者ID:Rhaeo,項目名稱:Rhaeo.Stun,代碼行數:18,代碼來源:StunMessage.cs

示例13: Parse

    public static StunMessageType Parse(Bits bits)
    {
      if (bits.Count != 14)
      {
        throw new ArgumentException("The number of bits must be 14.", nameof(bits));
      }

      var methodBits = new Bits(12);
      var classBits = new Bits(2);

      methodBits.AddBits(bits.PopBits(5));
      classBits.AddBit(bits.Pop());
      methodBits.AddBits(bits.PopBits(3));
      classBits.AddBit(bits.Pop());
      methodBits.AddBits(bits);

      return new StunMessageType(StunMessageMethod.Parse(methodBits), StunMessageClass.Parse(classBits));
    }
開發者ID:Rhaeo,項目名稱:Rhaeo.Stun,代碼行數:18,代碼來源:StunMessageType.cs

示例14: Main

        static void Main(string[] args)
        {
            //INPUT
            uint numN = uint.Parse(Console.ReadLine());
            List<int> startPos = new List<int>();
            for (int i =0; i<2;i++)
            {
                startPos.Add(int.Parse(Console.ReadLine()));
            }
            int modK = int.Parse(Console.ReadLine());

            //Create Bits
            List<Bits>[] toSwap = new List<Bits>[startPos.Count];
            for (int i = 0; i < toSwap.Length; i++)
            {
                toSwap[i] = new List<Bits>();
                for (int b = startPos[i]; b < startPos[i] + modK; b++)
                {
                    Bits bit = new Bits(0, b);
                    toSwap[i].Add(bit);
                }
            }
            //Assign Value to all bits
            for (int i = 0; i < toSwap.Length; i++)
            {
                for(int b = 0; b< toSwap[i].Count; b++)
                {
                    toSwap[i][b].Value = GetValue(numN, toSwap[i][b].Position);
                }
            }
            //switch Bits
            for (int i = 0; i < toSwap.Length-1; i++)
            {
                for(int b = 0; b < toSwap[i].Count;b++ )
                {
                    numN = SwapBits(numN, toSwap[i][b].Value, toSwap[i + 1][b].Position);
                    numN = SwapBits(numN, toSwap[i+1][b].Value, toSwap[i][b].Position);
                }

            }

            Console.WriteLine((uint)numN);
        }
開發者ID:tvmarinov,項目名稱:Homework,代碼行數:43,代碼來源:BitSwapV2.cs

示例15: StunMessageType

    public StunMessageType(StunMessageMethod method, StunMessageClass @class)
    {
      if (!method.PermittedClasses.Contains(@class))
      {
        throw new ArgumentException($"The class {@class} is not permitted by the method {method}.", nameof(@class));
      }
      
      Name = method.Name + " " + @class.Name;

      var methodBits = new Bits(method.Bits);
      var classBits = new Bits(@class.Bits);
      var bits = new Bits(14);
      bits.AddBits(methodBits.PopBits(5));
      bits.AddBit(classBits.Pop());
      bits.AddBits(methodBits.PopBits(3));
      bits.AddBit(classBits.Pop());
      bits.AddBits(methodBits);

      Bits = bits.ToBitArray();
    }
開發者ID:Rhaeo,項目名稱:Rhaeo.Stun,代碼行數:20,代碼來源:StunMessageType.cs


注:本文中的Bits類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。