当前位置: 首页>>代码示例>>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;未经允许,请勿转载。