Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
OpenBitSetDISI.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator;
21 
22 namespace Lucene.Net.Util
23 {
24 
25  [Serializable]
27  {
28 
29  /// <summary>Construct an OpenBitSetDISI with its bits set
30  /// from the doc ids of the given DocIdSetIterator.
31  /// Also give a maximum size one larger than the largest doc id for which a
32  /// bit may ever be set on this OpenBitSetDISI.
33  /// </summary>
34  public OpenBitSetDISI(DocIdSetIterator disi, int maxSize):base(maxSize)
35  {
36  InPlaceOr(disi);
37  }
38 
39  /// <summary>Construct an OpenBitSetDISI with no bits set, and a given maximum size
40  /// one larger than the largest doc id for which a bit may ever be set
41  /// on this OpenBitSetDISI.
42  /// </summary>
43  public OpenBitSetDISI(int maxSize):base(maxSize)
44  {
45  }
46 
47  /// <summary> Perform an inplace OR with the doc ids from a given DocIdSetIterator,
48  /// setting the bit for each such doc id.
49  /// These doc ids should be smaller than the maximum size passed to the
50  /// constructor.
51  /// </summary>
52  public virtual void InPlaceOr(DocIdSetIterator disi)
53  {
54  int doc;
55  long size = Size();
56  while ((doc = disi.NextDoc()) < size)
57  {
58  FastSet(doc);
59  }
60  }
61 
62  /// <summary> Perform an inplace AND with the doc ids from a given DocIdSetIterator,
63  /// leaving only the bits set for which the doc ids are in common.
64  /// These doc ids should be smaller than the maximum size passed to the
65  /// constructor.
66  /// </summary>
67  public virtual void InPlaceAnd(DocIdSetIterator disi)
68  {
69  int bitSetDoc = NextSetBit(0);
70  int disiDoc;
71  while (bitSetDoc != - 1 && (disiDoc = disi.Advance(bitSetDoc)) != DocIdSetIterator.NO_MORE_DOCS)
72  {
73  Clear(bitSetDoc, disiDoc);
74  bitSetDoc = NextSetBit(disiDoc + 1);
75  }
76  if (bitSetDoc != - 1)
77  {
78  Clear(bitSetDoc, Size());
79  }
80  }
81 
82  /// <summary> Perform an inplace NOT with the doc ids from a given DocIdSetIterator,
83  /// clearing all the bits for each such doc id.
84  /// These doc ids should be smaller than the maximum size passed to the
85  /// constructor.
86  /// </summary>
87  public virtual void InPlaceNot(DocIdSetIterator disi)
88  {
89  int doc;
90  long size = Size();
91  while ((doc = disi.NextDoc()) < size)
92  {
93  FastClear(doc);
94  }
95  }
96 
97  /// <summary> Perform an inplace XOR with the doc ids from a given DocIdSetIterator,
98  /// flipping all the bits for each such doc id.
99  /// These doc ids should be smaller than the maximum size passed to the
100  /// constructor.
101  /// </summary>
102  public virtual void InPlaceXor(DocIdSetIterator disi)
103  {
104  int doc;
105  long size = Size();
106  while ((doc = disi.NextDoc()) < size)
107  {
108  FastFlip(doc);
109  }
110  }
111  }
112 }