public Set <TEnum> Intersect(Set <TEnum> otherSet) { if (otherSet != null) { members.And(otherSet.members); } return(this); }
// intersection public static Set <TEnum> operator &(Set <TEnum> left, Set <TEnum> right) { System.Collections.BitArray result = new System.Collections.BitArray(new bool[left.members.Count]); result.Or(left.members); if (right != null) { result.And(right.members); } return(new Set <TEnum>(result)); }
internal virtual System.Collections.BitArray AddClause(BooleanQuery bq, System.Collections.BitArray result) { System.Collections.BitArray rnd = sets[r.Next(sets.Length)]; Query q = new ConstantScoreQuery(new AnonymousClassFilter(rnd, this)); bq.Add(q, BooleanClause.Occur.MUST); if (validate) { if (result == null) { result = (System.Collections.BitArray)rnd.Clone(); } else { result.And(rnd); } } return(result); }
/// <summary> Test if set A is contained in set B.</summary> /// <param name="A"> a bitSet /// </param> /// <param name="B"> a bitSet /// </param> /// <returns> true if A is contained in B /// </returns> private bool isContainedIn(System.Collections.BitArray A, System.Collections.BitArray B) { bool result = false; if (isEmpty(A)) { return(true); } System.Collections.BitArray setA = (System.Collections.BitArray)A.Clone(); //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.And' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'" setA.And(B); //UPGRADE_TODO: Method 'java.util.BitSet.equals' was converted to 'System.Collections.BitArray.Equals' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilBitSetequals_javalangObject'" if (setA.Equals(A)) { result = true; } return(result); }
public virtual void calcSelectedMonomersCount(System.Collections.BitArray bsSelected) { selectedMonomerCount = 0; if (bsSelectedMonomers == null) { bsSelectedMonomers = new System.Collections.BitArray(64); } else { //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.And' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'" bsSelectedMonomers.And(bsNull); } for (int i = monomerCount; --i >= 0;) { if (monomers[i].isSelected(bsSelected)) { ++selectedMonomerCount; SupportClass.BitArraySupport.Set(bsSelectedMonomers, i); } } }
public static void ValidateArrayElement4() { Stopwatch sp = new Stopwatch(); sp.Start(); Random rand = new Random(); Int32 maxValue = 120000; //元素最大值,是一个假定值 Int32 length = 70000; // A,B的长度 System.Collections.BitArray A = new System.Collections.BitArray(maxValue, false); System.Collections.BitArray B = new System.Collections.BitArray(maxValue, false); System.Collections.BitArray C = new System.Collections.BitArray(maxValue, false); for (int i = 0; i < length; i++) { A.Set(rand.Next(maxValue - 1), true); B.Set(rand.Next(maxValue - 1), true); } C = A.And(B); sp.Stop(); //停止计时 Console.WriteLine(sp.ElapsedTicks); //计时周期。因为毫秒太大了无法比较 }
public void And_Test(int[] bits1, int[] bits2) { var size = 12; var array1 = CreateArray(size); var array2 = CreateArray(size); var expected1 = new System.Collections.BitArray(size); var expected2 = new System.Collections.BitArray(size); foreach (var bit in bits1) { array1[bit] = expected1[bit] = true; } foreach (var bit in bits2) { array2[bit] = expected2[bit] = true; } var array = array1.And(array2); var expected = expected1.And(expected2); CollectionAssert.AreEqual(array, expected); Assert.AreEqual(expected.Count, array.Count); }
/// <summary> Parsing of the RGraph. This is the recursive method /// to perform a query. The method will recursively /// parse the RGraph thru connected nodes and visiting the /// RGraph using allowed adjacency relationship. /// /// </summary> /// <param name="traversed"> node already parsed /// </param> /// <param name="extension"> possible extension node (allowed neighbours) /// </param> /// <param name="forbiden"> node forbiden (set of node incompatible with the current solution) /// </param> private void parseRec(System.Collections.BitArray traversed, System.Collections.BitArray extension, System.Collections.BitArray forbidden) { System.Collections.BitArray newTraversed = null; System.Collections.BitArray newExtension = null; System.Collections.BitArray newForbidden = null; System.Collections.BitArray potentialNode = null; // if there is no more extension possible we // have reached a potential new solution if (isEmpty(extension)) { solution(traversed); } // carry on with each possible extension else { // calculates the set of nodes that may still // be reached at this stage (not forbiden) potentialNode = ((System.Collections.BitArray)graphBitSet.Clone()); potentialNode.And(forbidden.Not()); //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'" potentialNode.Or(traversed); // checks if we must continue the search // according to the potential node set if (mustContinue(potentialNode)) { // carry on research and update iteration count nbIteration++; // for each node in the set of possible extension (neighbours of // the current partial solution, include the node to the solution // and perse recursively the RGraph with the new context. for (int x = nextSetBit(extension, 0); x >= 0 && !stop; x = nextSetBit(extension, x + 1)) { // evaluates the new set of forbidden nodes // by including the nodes not compatible with the // newly accepted node. newForbidden = (System.Collections.BitArray)forbidden.Clone(); //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'" newForbidden.Or(((RNode)graph[x]).forbidden); // if it is the first time we are here then // traversed is empty and we initialize the set of // possible extensions to the extension of the first // accepted node in the solution. if (isEmpty(traversed)) { newExtension = (System.Collections.BitArray)(((RNode)graph[x]).extension.Clone()); } // else we simply update the set of solution by // including the neighbours of the newly accepted node else { newExtension = (System.Collections.BitArray)extension.Clone(); //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'" newExtension.Or(((RNode)graph[x]).extension); } // extension my not contain forbidden nodes newExtension.And(newForbidden.Not()); // create the new set of traversed node // (update current partial solution) // and add x to the set of forbidden node // (a node may only appear once in a solution) newTraversed = (System.Collections.BitArray)traversed.Clone(); SupportClass.BitArraySupport.Set(newTraversed, x); SupportClass.BitArraySupport.Set(forbidden, x); // parse recursively the RGraph parseRec(newTraversed, newExtension, newForbidden); } } } }
static void Main(string[] args) { #region https://youtu.be/_UtKEYYhi24 Coleccion show = new Coleccion(); System.Collections.BitArray bitArray = new System.Collections.BitArray( new byte[] { 1, 2, 4, 8, 16 });// Convertiendo byte a bit CountElement.Count(bitArray); Coleccion.Show(bitArray, 2); //// Obtenemos un bit en particular System.Console.WriteLine(bitArray.Get(3)); //// ponemos un bit en particular bitArray.Set(3, true); System.Console.WriteLine(bitArray.Get(3)); Coleccion.Show(bitArray, 2); //https://youtu.be/pGS78ttnqfY // Clonacion del BitArray System.Collections.BitArray bitArray2 = (System.Collections.BitArray)bitArray.Clone(); //// Invertir el Array, NOT bitArray2.Not(); Coleccion.Show(bitArray2, 2); // Creando otro Array System.Collections.BitArray bitArray3 = new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 15 }); Coleccion.Show(bitArray3, 2, "3°Array"); //// Hacemos Or entre Arreglos bitArray3.Or(bitArray); // El resultado se guarda en el Array que llevo //acabo la invocacion. Coleccion.Show(bitArray, pNombre: "1°Array"); Coleccion.Show(bitArray3, 3, pNombre: "Result"); System.Console.WriteLine("=|||||||||="); //// Hacemos AND entre Array Coleccion.Show(bitArray, pNombre: "1°Array"); Coleccion.Show(bitArray3, pNombre: "3°Array"); // Hacemos el AND, BitArray 3 se modifica con el resultado bitArray3.And(bitArray); Coleccion.Show(bitArray3, 3, "Result"); System.Console.WriteLine("=&&&&&&&&&&&="); //// Hamos XOR entre Array bitArray3 = new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 21 }); Coleccion.Show(bitArray, pNombre: "1°Array"); Coleccion.Show(bitArray3, pNombre: "3°Array"); // Hacemos el XOR, Array 3 se modifica con el resultado bitArray3.Xor(bitArray); Coleccion.Show(bitArray3, pNombre: "Result"); System.Console.ReadKey(); #endregion }