public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bitset = new System.Collections.BitArray((5 % 64 == 0?5 / 64:5 / 64 + 1) * 64); bitset.Set(1, true); bitset.Set(3, true); return bitset; }
public static byte[] GetBitsfromArray(List <bool> answers) { byte[] bytearray = new byte[1]; var bitArray = new System.Collections.BitArray(bytearray); var index = 0; foreach (var answer in answers) { if (answer == true) { bitArray.Set(index, true); } else { bitArray.Set(index, false); } index++; } bitArray.Set(6, false); bitArray.Set(7, false); bitArray.CopyTo(bytearray, 0); return(bytearray); }
public override DocIdSet GetDocIdSet(IndexReader reader) { System.Collections.BitArray bitset = new System.Collections.BitArray((5 % 64 == 0?5 / 64:5 / 64 + 1) * 64); bitset.Set(1, true); bitset.Set(3, true); return new DocIdBitSet(bitset); }
public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bitset = new System.Collections.BitArray((5 % 64 == 0?5 / 64:5 / 64 + 1) * 64); bitset.Set(1, true); bitset.Set(3, true); return(bitset); }
public static byte[] GetBitsFromString(string answer) { byte[] bytearray = new byte[1]; var bitArray = new System.Collections.BitArray(bytearray); var index = 0; foreach (char c in answer) { if (c == '1') { bitArray.Set(index, true); } else { bitArray.Set(index, false); } index++; } bitArray.Set(6, false); bitArray.Set(7, false); bitArray.CopyTo(bytearray, 0); return(bytearray); }
public override DocIdSet GetDocIdSet(IndexReader reader) { System.Collections.BitArray bitset = new System.Collections.BitArray((5 % 64 == 0?5 / 64:5 / 64 + 1) * 64); bitset.Set(1, true); bitset.Set(3, true); return(new DocIdBitSet(bitset)); }
static UriUtility() { #if PORTABLE if (!Enum.TryParse("Compiled", out DefaultRegexOptions)) DefaultRegexOptions = RegexOptions.None; #else DefaultRegexOptions = RegexOptions.Compiled; #endif _unreservedCharacters = new BitArray(256); for (char i = 'a'; i <= 'z'; i++) _unreservedCharacters.Set(i, true); for (char i = 'A'; i <= 'Z'; i++) _unreservedCharacters.Set(i, true); for (char i = '0'; i <= '9'; i++) _unreservedCharacters.Set(i, true); _unreservedCharacters.Set('-', true); _unreservedCharacters.Set('.', true); _unreservedCharacters.Set('_', true); _unreservedCharacters.Set('~', true); _generalDelimiters = new BitArray(256); _generalDelimiters.Set(':', true); _generalDelimiters.Set('/', true); _generalDelimiters.Set('?', true); _generalDelimiters.Set('#', true); _generalDelimiters.Set('[', true); _generalDelimiters.Set(']', true); _generalDelimiters.Set('@', true); _subDelimiters = new BitArray(256); _subDelimiters.Set('!', true); _subDelimiters.Set('$', true); _subDelimiters.Set('&', true); _subDelimiters.Set('(', true); _subDelimiters.Set(')', true); _subDelimiters.Set('*', true); _subDelimiters.Set('+', true); _subDelimiters.Set(',', true); _subDelimiters.Set(';', true); _subDelimiters.Set('=', true); _subDelimiters.Set('\'', true); _reservedCharacters = new BitArray(256).Or(_generalDelimiters).Or(_subDelimiters); _allowedHostCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters); _allowedPathCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters); _allowedPathCharacters.Set(':', true); _allowedPathCharacters.Set('@', true); _allowedQueryCharacters = new BitArray(256).Or(_allowedPathCharacters); _allowedQueryCharacters.Set('/', true); _allowedQueryCharacters.Set('?', true); _allowedFragmentCharacters = new BitArray(256).Or(_allowedPathCharacters); _allowedFragmentCharacters.Set('/', true); _allowedFragmentCharacters.Set('?', true); }
public static void Swap(this System.Collections.BitArray instance, int indexA, int indexB) { bool current = instance.Get(indexA); bool swap = instance.Get(indexB); instance.Set(indexA, swap); instance.Set(indexB, current); }
static UriUtility() { _unreservedCharacters = new BitArray(256); for (char i = 'a'; i <= 'z'; i++) { _unreservedCharacters.Set(i, true); } for (char i = 'A'; i <= 'Z'; i++) { _unreservedCharacters.Set(i, true); } for (char i = '0'; i <= '9'; i++) { _unreservedCharacters.Set(i, true); } _unreservedCharacters.Set('-', true); _unreservedCharacters.Set('.', true); _unreservedCharacters.Set('_', true); _unreservedCharacters.Set('~', true); _generalDelimiters = new BitArray(256); _generalDelimiters.Set(':', true); _generalDelimiters.Set('/', true); _generalDelimiters.Set('?', true); _generalDelimiters.Set('#', true); _generalDelimiters.Set('[', true); _generalDelimiters.Set(']', true); _generalDelimiters.Set('@', true); _subDelimiters = new BitArray(256); _subDelimiters.Set('!', true); _subDelimiters.Set('$', true); _subDelimiters.Set('&', true); _subDelimiters.Set('(', true); _subDelimiters.Set(')', true); _subDelimiters.Set('*', true); _subDelimiters.Set('+', true); _subDelimiters.Set(',', true); _subDelimiters.Set(';', true); _subDelimiters.Set('=', true); _subDelimiters.Set('\'', true); _reservedCharacters = new BitArray(256).Or(_generalDelimiters).Or(_subDelimiters); _allowedHostCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters); _allowedPathCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters); _allowedPathCharacters.Set(':', true); _allowedPathCharacters.Set('@', true); _allowedQueryCharacters = new BitArray(256).Or(_allowedPathCharacters); _allowedQueryCharacters.Set('/', true); _allowedQueryCharacters.Set('?', true); _allowedFragmentCharacters = new BitArray(256).Or(_allowedPathCharacters); _allowedFragmentCharacters.Set('/', true); _allowedFragmentCharacters.Set('?', true); }
void streaming_BufferEnd(object sender, ContextEventArgs e) { lock (mutex) { // Unset the bit for the completed buffer bufferStatus.Set((int)e.Context, false); // Signal to the DecoderThread System.Threading.Monitor.Pulse(mutex); } }
static UriUtility() { _unreservedCharacters = new BitArray(256); for (char i = 'a'; i <= 'z'; i++) _unreservedCharacters.Set(i, true); for (char i = 'A'; i <= 'Z'; i++) _unreservedCharacters.Set(i, true); for (char i = '0'; i <= '9'; i++) _unreservedCharacters.Set(i, true); _unreservedCharacters.Set('-', true); _unreservedCharacters.Set('.', true); _unreservedCharacters.Set('_', true); _unreservedCharacters.Set('~', true); _generalDelimiters = new BitArray(256); _generalDelimiters.Set(':', true); _generalDelimiters.Set('/', true); _generalDelimiters.Set('?', true); _generalDelimiters.Set('#', true); _generalDelimiters.Set('[', true); _generalDelimiters.Set(']', true); _generalDelimiters.Set('@', true); _subDelimiters = new BitArray(256); _subDelimiters.Set('!', true); _subDelimiters.Set('$', true); _subDelimiters.Set('&', true); _subDelimiters.Set('(', true); _subDelimiters.Set(')', true); _subDelimiters.Set('*', true); _subDelimiters.Set('+', true); _subDelimiters.Set(',', true); _subDelimiters.Set(';', true); _subDelimiters.Set('=', true); _subDelimiters.Set('\'', true); _reservedCharacters = new BitArray(256).Or(_generalDelimiters).Or(_subDelimiters); _allowedHostCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters); _allowedPathCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters); _allowedPathCharacters.Set(':', true); _allowedPathCharacters.Set('@', true); _allowedQueryCharacters = new BitArray(256).Or(_allowedPathCharacters); _allowedQueryCharacters.Set('/', true); _allowedQueryCharacters.Set('?', true); _allowedFragmentCharacters = new BitArray(256).Or(_allowedPathCharacters); _allowedFragmentCharacters.Set('/', true); _allowedFragmentCharacters.Set('?', true); }
/// <summary> /// 消息处理 /// </summary> /// <param name="message"></param> private void onMessage(Message message) { System.Threading.Monitor.Enter(onMessageLock); if (message != null && !bitArray.Get(message.Value)) { bitArray.Set(message.Value, true); setCallback(true); } else { setCallback(false); } System.Threading.Monitor.Exit(onMessageLock); }
public System.Collections.BitArray GetClusterBitArray() { int totalClusters = (int)Utilities.Ceil(_self.Context.BiosParameterBlock.TotalSectors64, _self.Context.BiosParameterBlock.SectorsPerCluster); System.Collections.BitArray ba = new System.Collections.BitArray(totalClusters, false); foreach (FileRecord fr in Records) { if (fr.BaseFile.Value != 0) { continue; } File f = new File(_self.Context, fr); foreach (var stream in f.AllStreams) { foreach (var range in stream.GetClusters()) { for (long cluster = range.Offset; cluster < range.Offset + range.Count; ++cluster) { if (cluster < totalClusters) { ba.Set((int)cluster, true); } } } } } return(ba); }
/// <summary> Returns a BitSet with true for documents which should be /// permitted in search results, and false for those that should /// not. /// </summary> public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); TermEnum enumerator = reader.Terms(new Term(field, start)); TermDocs termDocs = reader.TermDocs(); if (enumerator.Term() == null) { return(bits); } try { Term stop = new Term(field, end); while (enumerator.Term().CompareTo(stop) <= 0) { termDocs.Seek(enumerator.Term()); while (termDocs.Next()) { bits.Set(termDocs.Doc(), true); } if (!enumerator.Next()) { break; } } } finally { enumerator.Close(); termDocs.Close(); } return(bits); }
/// <summary> /// Если идентификатор еще не отмеченный, то отметим его, если идентификатор уже отмеченный, то поместим значение mT в словарь /// </summary> /// <param name="bitArr"></param> /// <param name="hash"></param> /// <param name="lastDefs"></param> /// <param name="id"></param> /// <param name="mTval">отметка времени. null - минимальное время</param> private static void CheckAndSet(System.Collections.BitArray bitArr, Func <string, int> hash, Dictionary <string, DateTime> lastDefs, string id, string mTval) { int code = hash(id); if (bitArr.Get(code)) { // Добавляем пару в словарь DateTime mT = DateTime.MinValue; if (mTval != null) { mT = DateTime.Parse(mTval); } if (lastDefs.TryGetValue(id, out DateTime last)) { if (mT > last) { lastDefs.Remove(id); lastDefs.Add(id, mT); } } else { lastDefs.Add(id, mT); } } else { bitArr.Set(code, true); } }
private string ReadFromWriteResult(Domain.Writers.Dtos.MessageWriteResult writeResult) { string resultMessage = null; ushort byteThresholdBitCounter = 0; var bitArray = new System.Collections.BitArray(8); var messageRetrievedFromResultBuffer = new System.Collections.Generic.List <byte>(); for (int byteIndex = 0; byteIndex < writeResult.TotalNumberOfBytesUsed; byteIndex++) { var currentByte = writeResult.Buffer[byteIndex]; for (ushort bitInBytePositionCounter = 0; bitInBytePositionCounter < writeResult.NumberOfBitsUsedInByte; bitInBytePositionCounter++) { var bit = ((currentByte & (1 << bitInBytePositionCounter)) != 0); bitArray.Set(byteThresholdBitCounter, bit); byteThresholdBitCounter++; if (byteThresholdBitCounter == 8) { var byteStorage = new byte[1]; bitArray.CopyTo(byteStorage, 0); messageRetrievedFromResultBuffer.Add(byteStorage[0]); bitArray.SetAll(false); byteThresholdBitCounter = 0; } } } resultMessage = System.Text.Encoding.UTF8.GetString(messageRetrievedFromResultBuffer.ToArray()); return(resultMessage); }
public static bool TryParse(AddressFamily addressFamily, string value, out IPRange result) { result = null; int num; if (addressFamily == AddressFamily.InterNetwork) { num = 32; } else { if (addressFamily != AddressFamily.InterNetworkV6) { return(false); } num = 128; } if (string.IsNullOrEmpty(value)) { return(false); } System.Collections.BitArray bitArray = new System.Collections.BitArray(num, true); int num2 = value.IndexOf('/'); if (num2 >= 0) { int num3 = num; string text = value.Substring(num2 + 1); value = value.Substring(0, num2); if (int.TryParse(text, out num3)) { if (num3 >= 0 && num3 <= num) { for (int i = num3; i < num; i++) { bitArray.Set(i, false); } } } else { IPAddress iPAddress; if (IPAddress.TryParse(text, out iPAddress)) { bitArray = new System.Collections.BitArray(iPAddress.GetAddressBytes()); } } } IPAddress iPAddress2; if (IPAddress.TryParse(value, out iPAddress2)) { byte[] addressBytes = iPAddress2.GetAddressBytes(); byte[] array = new byte[addressBytes.Length]; bitArray.CopyTo(array, 0); result = new IPRange(addressFamily, addressBytes, array); return(true); } return(false); }
/// <inheritdoc/> protected override void BuildPatternBodyImpl(StringBuilder pattern, ICollection <string> requiredVariables, ICollection <string> arrayVariables, ICollection <string> mapVariables) { if (pattern == null) { throw new ArgumentNullException("pattern"); } if (arrayVariables == null) { throw new ArgumentNullException("arrayVariables"); } if (mapVariables == null) { throw new ArgumentNullException("mapVariables"); } BitArray requiredPatterns = new BitArray(Variables.Count); List <string> variablePatterns = new List <string>(); for (int i = 0; i < Variables.Count; i++) { VariableReference variable = Variables[i]; if (requiredVariables.Contains(variable.Name)) { requiredPatterns.Set(i, true); } bool allowReservedSet = true; variablePatterns.Add(BuildVariablePattern(variable, allowReservedSet, null, requiredVariables, arrayVariables, mapVariables)); } pattern.Append("(?:#"); AppendOneOrMoreToEnd(pattern, requiredPatterns, variablePatterns, 0); pattern.Append(")?"); }
protected override void BuildPatternBodyImpl(StringBuilder pattern, ICollection<string> requiredVariables, ICollection<string> arrayVariables, ICollection<string> mapVariables) { if (pattern == null) throw new ArgumentNullException("pattern"); if (arrayVariables == null) throw new ArgumentNullException("arrayVariables"); if (mapVariables == null) throw new ArgumentNullException("mapVariables"); BitArray requiredPatterns = new BitArray(Variables.Count); List<string> variablePatterns = new List<string>(); for (int i = 0; i < Variables.Count; i++) { VariableReference variable = Variables[i]; if (requiredVariables.Contains(variable.Name)) requiredPatterns.Set(i, true); bool allowReservedSet = false; variablePatterns.Add(BuildVariablePattern(variable, allowReservedSet, null, requiredVariables, arrayVariables, mapVariables)); } pattern.Append("(?:"); AppendZeroOrMoreToEnd(pattern, requiredPatterns, variablePatterns, 0); pattern.Append(")"); }
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /// <summary>Add a single terminal to the set. /// </summary> /// <param name="sym">the terminal being added. /// </param> /// <returns>true if this changes the set. /// /// </returns> public virtual bool add(terminal sym) { bool result; not_null(sym); /* see if we already have this */ result = _elements.Get(sym.index()); /* if not we add it */ if (!result) { _elements.Set(sym.index(), true); } return(result); }
public override void Collect(int doc) { for (int i = 0; doc + base_Renamed >= bits.Length; i = +64) { bits.Length += i; } bits.Set(doc + base_Renamed, true); // set bit for hit }
public virtual System.Collections.BitArray RandBitSet(int sz, int numBitsToSet) { System.Collections.BitArray set_Renamed = new System.Collections.BitArray((sz % 64 == 0?sz / 64:sz / 64 + 1) * 64); for (int i = 0; i < numBitsToSet; i++) { set_Renamed.Set(r.Next(sz), true); } return(set_Renamed); }
public override DocIdSet GetDocIdSet(IndexReader reader) { System.Collections.BitArray bitset = new System.Collections.BitArray((5 % 64 == 0?5 / 64:5 / 64 + 1) * 64); for (int i = 0; i < 5; i++) { bitset.Set(i, true); } return(new DocIdBitSet(bitset)); }
private System.Collections.BitArray CloneBitArray(System.Collections.BitArray inBits, int start, int len) { System.Collections.BitArray rslt = new System.Collections.BitArray(len); for (int i = 0; i < len; i++) { rslt.Set(i, inBits.Get(i + start)); } return(rslt); }
public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bitset = new System.Collections.BitArray((5 % 64 == 0 ? 5 / 64 : 5 / 64 + 1) * 64); for (int i = 0; i < 5; i++) { bitset.Set(i, true); } return bitset; }
/// <summary> /// Creates an object to hold a particular TableEntry. /// </summary> /// <param name="bytes">The bytes from which to make the TableEntry.</param> public TableEntry(byte[] bytes) { System.Collections.BitArray ba = new System.Collections.BitArray(bytes); Compressed = ba.Get(31); ba.Set(31, false); byte[] temp = new byte[4]; ba.CopyTo(temp, 0); Offset = BitConverter.ToInt32(temp, 0); }
public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64); for (int increment = 0; doc >= bits.Length; increment =+ 64) { bits.Length += increment; } bits.Set(doc, true); return bits; }
public void Add(byte[] data) { if (data.Length == 1 && data[0] == 0xFF) { return; } for (int i = 0; i < HashFunctions; ++i) { int index = Hash(i, data); Bits.Set(index, true); } }
public virtual void TestRepeatedRollBacks() { int expectedLastRecordId = 100; while (expectedLastRecordId > 10) { expectedLastRecordId -= 10; RollBackLast(expectedLastRecordId); System.Collections.BitArray expecteds = new System.Collections.BitArray((100 % 64 == 0?100 / 64:100 / 64 + 1) * 64); for (int i = 1; i < (expectedLastRecordId + 1); i++) { expecteds.Set(i, true); } CheckExpecteds(expecteds); } }
public static System.Collections.BitArray StringToBitArray(string str) { System.Collections.BitArray bit = new System.Collections.BitArray(str.Length, false); for (int i = 0; i < str.Length; i++) { switch (str[i]) { case '1': bit.Set(i, true); break; } } return(bit); }
public static System.Collections.BitArray UndoResolutionArray(System.Collections.BitArray[] bitArrays) { int bitres = bitArrays[0].Length; System.Collections.BitArray outArray = new System.Collections.BitArray(bitArrays.Length * bitres); for (int i = 0; i < bitArrays.Length; ++i) { for (int j = 0; j < bitres; j++) { outArray.Set(i * bitres + j, bitArrays[i].Get(j)); } } return(outArray); }
override public void Run() { if (withTimeout) { Enclosing_Instance.DoTestTimeout(true, true); } else { Enclosing_Instance.DoTestSearch(); } lock (success.SyncRoot) { success.Set(num, true); } }
private static System.Collections.BitArray Xor(System.Collections.BitArray bitArray, System.Collections.BitArray bitArray2) { //System.Collections.BitArray bitArray3 = new System.Collections.BitArray(bitArray); //System.Collections.BitArray bitArray4 = new System.Collections.BitArray(bitArray2); //return new System.Collections.BitArray(bitArray3).Xor(bitArray4); System.Collections.BitArray bitArray3 = new System.Collections.BitArray(bitArray.Count); for (int i = 0; i < bitArray.Count; i++) { if (bitArray[i] ^ bitArray2[i]) { bitArray3.Set(i, true); } } return(bitArray3); }
public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter) { int ret = 0; long nMatches = 0; for (int i = 0; i < iter; i++) { int oClauses = r.Next(maxOuterClauses - 1) + 2; BooleanQuery oq = new BooleanQuery(); for (int o = 0; o < oClauses; o++) { int nClauses = r.Next(maxClauses - 1) + 2; // min 2 clauses BooleanQuery bq = new BooleanQuery(); System.Collections.BitArray termflag = new System.Collections.BitArray((termsInIndex % 64 == 0?termsInIndex / 64:termsInIndex / 64 + 1) * 64); for (int j = 0; j < nClauses; j++) { int tnum; // don't pick same clause twice tnum = r.Next(termsInIndex); if (termflag.Get(tnum)) { tnum = SupportClass.BitSetSupport.NextClearBit(termflag, tnum); } if (tnum < 0 || tnum >= 25) { tnum = SupportClass.BitSetSupport.NextClearBit(termflag, 0); } termflag.Set(tnum, true); Query tq = new TermQuery(terms[tnum]); bq.Add(tq, BooleanClause.Occur.MUST); } // inner oq.Add(bq, BooleanClause.Occur.MUST); } // outer CountingHitCollector hc = new CountingHitCollector(); s.Search(oq, hc); nMatches += hc.GetCount(); ret += hc.GetSum(); } System.Console.Out.WriteLine("Average number of matches=" + (nMatches / iter)); return(ret); }
private void button_update_Click(object sender, EventArgs e) { System.Collections.BitArray bl, re, gr; bl = new System.Collections.BitArray(bitsfield.Count / 3); re = new System.Collections.BitArray(bitsfield.Count / 3); gr = new System.Collections.BitArray(bitsfield.Count / 3); Byte[] b = new Byte[resol * led_count / 8]; Byte[] r = new Byte[resol * led_count / 8]; Byte[] g = new Byte[resol * led_count / 8]; for (int i = 0; i < bitsfield.Count; i += 24) { for (int j = 0; j < 8; j++) { bl.Set(i / 3 + j, bitsfield.Get(i + (7 - j) * 3)); re.Set(i / 3 + j, bitsfield.Get(i + (7 - j) * 3 + 1)); gr.Set(i / 3 + j, bitsfield.Get(i + (7 - j) * 3 + 2)); } } bl.CopyTo(b, 0); re.CopyTo(r, 0); gr.CopyTo(g, 0); String Bdata = ""; String Rdata = ""; String Gdata = ""; for (int i = 0; i < (resol * led_count / 8); i++) { Bdata += BitConverter.ToString(b, i, 1); Rdata += BitConverter.ToString(r, i, 1); Gdata += BitConverter.ToString(g, i, 1); } String txt = ""; for (int i = 0; i < (resol * led_count / 4); i += (led_count / 4)) { txt += "0x"; txt += Bdata.Substring(i, (led_count / 4)); txt += ", 0x"; txt += Rdata.Substring(i, (led_count / 4)); txt += ", 0x"; txt += Gdata.Substring(i, (led_count / 4)); txt += ",\r\n"; } this.textBox_data.Text = txt; }
public override void Collect(int docId, float score) { if (slowdown > 0) { try { System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * slowdown)); } catch (System.Threading.ThreadInterruptedException ie) { SupportClass.ThreadClass.Current().Interrupt(); throw new System.SystemException("", ie); } } System.Diagnostics.Debug.Assert(docId >= 0, "doc=" + docId); bits.Length = Math.Max(bits.Length, docId + 1); bits.Set(docId, true); lastDocCollected = docId; }
internal static void corrupt(int[] received, int howMany, Random random) { var corrupted = new System.Collections.BitArray(received.Length); //BitSet corrupted = new BitSet(received.Length); for (int j = 0; j < howMany; j++) { int location = random.Next(received.Length); if (corrupted[location]) { j--; } else { corrupted.Set(location, true); received[location] = (received[location] + 1 + random.Next(255)) & 0xFF; } } }
public virtual void Test() { PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper(); mapper.SetExpectations("test", tokens.Length, true, true); //Test single position for (int i = 0; i < tokens.Length; i++) { System.String token = tokens[i]; mapper.Map(token, 1, null, thePositions[i]); } var map = mapper.FieldToTerms; Assert.IsTrue(map != null, "map is null and it shouldn't be"); Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1); var positions = map["test"]; Assert.IsNotNull(positions, "thePositions is null and it shouldn't be"); Assert.AreEqual(numPositions, positions.Count, "thePositions Size: " + positions.Count + " is not: " + numPositions); System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64); for (var iterator = positions.GetEnumerator(); iterator.MoveNext();) { var entry = iterator.Current; PositionBasedTermVectorMapper.TVPositionInfo info = entry.Value; Assert.IsTrue(info != null, "info is null and it shouldn't be"); int pos = (int)entry.Key; bits.Set(pos, true); Assert.IsTrue(info.Position == pos, info.Position + " does not equal: " + pos); Assert.IsTrue(info.Offsets != null, "info.getOffsets() is null and it shouldn't be"); if (pos == 0) { Assert.IsTrue(info.Terms.Count == 2, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 2); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 2, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 2); } else { Assert.IsTrue(info.Terms.Count == 1, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 1); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 1, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 1); } } Assert.IsTrue(BitSetSupport.Cardinality(bits) == numPositions, "Bits are not all on"); }
public virtual void TstViaBitSet(int[] ints, int expectedByteSize) { int MAX_INT_FOR_BITSET = 1024 * 1024; //mgarski - BitArray cannot grow, so make as large as we would need it to be System.Collections.BitArray bs = new System.Collections.BitArray(MAX_INT_FOR_BITSET); for (int i = 0; i < ints.Length; i++) { if (ints[i] > MAX_INT_FOR_BITSET) { return ; // BitSet takes too much memory } if ((i > 0) && (ints[i - 1] == ints[i])) { return ; // BitSet cannot store duplicate. } bs.Set(ints[i], true); } SortedVIntList svil = new SortedVIntList(bs); TstVIntList(svil, ints, expectedByteSize); TstVIntList(new SortedVIntList(svil.Iterator()), ints, expectedByteSize); }
public override SpanFilterResult BitSpans(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64); Lucene.Net.Search.Spans.Spans spans = query.GetSpans(reader); System.Collections.IList tmp = new System.Collections.ArrayList(20); int currentDoc = - 1; SpanFilterResult.PositionInfo currentInfo = null; while (spans.Next()) { int doc = spans.Doc(); bits.Set(doc, true); if (currentDoc != doc) { currentInfo = new SpanFilterResult.PositionInfo(doc); tmp.Add(currentInfo); currentDoc = doc; } currentInfo.AddPosition(spans.Start(), spans.End()); } return new SpanFilterResult(bits, tmp); }
/// <summary> Returns a BitSet with true for documents which should be /// permitted in search results, and false for those that should /// not. /// </summary> public override System.Collections.BitArray Bits(Monodoc.Lucene.Net.Index.IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); TermEnum enumerator = reader.Terms(new Term(field, start)); TermDocs termDocs = reader.TermDocs(); if (enumerator.Term() == null) { return bits; } try { Term stop = new Term(field, end); while (enumerator.Term().CompareTo(stop) <= 0) { termDocs.Seek(enumerator.Term()); while (termDocs.Next()) { bits.Set(termDocs.Doc(), true); } if (!enumerator.Next()) { break; } } } finally { enumerator.Close(); termDocs.Close(); } return bits; }
public virtual int DoNestedTermConjunctions(IndexSearcher s, int termsInIndex, int maxOuterClauses, int maxClauses, int iter) { int ret = 0; long nMatches = 0; for (int i = 0; i < iter; i++) { int oClauses = r.Next(maxOuterClauses - 1) + 2; BooleanQuery oq = new BooleanQuery(); for (int o = 0; o < oClauses; o++) { int nClauses = r.Next(maxClauses - 1) + 2; // min 2 clauses BooleanQuery bq = new BooleanQuery(); System.Collections.BitArray termflag = new System.Collections.BitArray((termsInIndex % 64 == 0 ? termsInIndex / 64 : termsInIndex / 64 + 1) * 64); for (int j = 0; j < nClauses; j++) { int tnum; // don't pick same clause twice tnum = r.Next(termsInIndex); if (termflag.Get(tnum)) { int nextClearBit = -1; for (int k = tnum + 1; k < termflag.Count; k++) { if (!termflag.Get(k)) { nextClearBit = k; break; } } tnum = nextClearBit; } if (tnum < 0 || tnum >= 25) { int nextClearBit = -1; for (int k = 0; k < termflag.Count; k++) { if (!termflag.Get(k)) { nextClearBit = k; break; } } tnum = nextClearBit; } termflag.Set(tnum, true); Query tq = new TermQuery(terms[tnum]); bq.Add(tq, BooleanClause.Occur.MUST); } // inner oq.Add(bq, BooleanClause.Occur.MUST); } // outer CountingHitCollector hc = new CountingHitCollector(); s.Search(oq, hc); nMatches += hc.GetCount(); ret += hc.GetSum(); } System.Console.Out.WriteLine("Average number of matches=" + (nMatches / iter)); return ret; }
void ReadingTask() { Stream stream=null; // byte[] tempdata;// = new byte[34]; while (true) { try { if (tcp == null || !tcp.Connected) { // Comm_state = 0; tcp = new TcpClient(); try { Console.WriteLine("Connect to Smr" + IP + ":" + Port); tcp.Connect(IP, Port); } catch (Exception exx) { Console.WriteLine(exx.Message); } } // 偵測 RTU開 斷線並產生事件 if (tcp != null && tcp.Connected) { Comm_state = 1; stream = tcp.GetStream(); stream.ReadTimeout = 3000; // int voltage=0; // int data; int voltage = 0, current = 0, mod1, mod2, mod3; int AcFail = 0, SmrWarning = 0, major = 0, minor = 0; byte[] rdata = new byte[32]; //while (true) //{ //if (stream.Length == 32 ) //{ int cks = 0; stream.Write(new byte[] { 0xaa, 0x02, 100, 2 + 100 }, 0, 4); // CSU 運作狀態 50d 32h stream.Flush(); try { stream.Read(rdata, 0, 32); } catch (Exception ex) { Console.WriteLine("SMR_RTU"+ex.Message); tcp.Close(); System.Threading.Thread.Sleep(1000); continue; } Console.WriteLine("read"); voltage = rdata[1] + rdata[2] * 256; current = rdata[3] + rdata[4] * 256; mod1 = rdata[13]; mod2 = rdata[14]; mod3 = rdata[15]; AcFail = ((mod1 >> 6) & 1); SmrWarning = ((mod1 >> 5) & 1); major = ((mod1 >> 3) & 1); minor = ((mod1 >> 4) & 1); Console.WriteLine("v:{0} i:{1} mod1={2:X2} mod2={3:X2} mod3={4:X2} major:{5} minor:{6} Acfail:{7} SmrWarning:{8}", voltage, current, mod1, mod2, mod3, major, minor, AcFail, SmrWarning); for (int i = 0; i < 32; i++) { cks += rdata[i]; Console.Write("{0:X2} ", rdata[i]); } cks -= rdata[31]; Console.WriteLine(); if ((cks & 255) != rdata[31]) Console.WriteLine("cks error {0:X2}!", cks & 255); byte[] retData = new byte[6]; retData[0] = (byte)(voltage / 256); retData[1] = (byte)(voltage % 256); retData[2] = (byte)(current / 256); retData[3] = (byte)(current % 256); retData[4] = 0; System.Collections.BitArray ba = new System.Collections.BitArray(new byte[] { 0 }); // bit 0 1 2 3 // major minor SmrWarning AcFail ba.Set(0, major == 0); ba.Set(1, minor == 0); ba.Set(2, SmrWarning == 0); ba.Set(3, AcFail == 0); ba.CopyTo(retData, 5); for (int i = 0; i < data.Length; i++) data[i] = retData[i]; } else { Comm_state = 0; } } catch (Exception ex) { Console.WriteLine("RTU:" + this.ControlID + "," + ex.Message + "," + ex.StackTrace); } System.Threading.Thread.Sleep(10000); } }
public override DocIdSet GetDocIdSet(IndexReader reader) { System.Collections.BitArray bs = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); for (int i = 0; i < reader.MaxDoc(); i++) bs.Set(i, true); bs.Set(docs1.ScoreDocs[0].Doc, true); return new DocIdBitSet(bs); }
public virtual System.Collections.BitArray RandBitSet(int sz, int numBitsToSet) { System.Collections.BitArray set_Renamed = new System.Collections.BitArray((sz % 64 == 0 ? sz / 64 : sz / 64 + 1) * 64); for (int i = 0; i < numBitsToSet; i++) { set_Renamed.Set(r.Next(sz), true); } return set_Renamed; }
internal virtual void DoRandomSets(int maxSize, int iter, int mode) { System.Collections.BitArray a0 = null; OpenBitSet b0 = null; for (int i = 0; i < iter; i++) { int sz = rand.Next(maxSize); System.Collections.BitArray a = new System.Collections.BitArray(sz); OpenBitSet b = new OpenBitSet(sz); // test the various ways of setting bits if (sz > 0) { int nOper = rand.Next(sz); for (int j = 0; j < nOper; j++) { int idx; idx = rand.Next(sz); a.Set(idx, true); b.FastSet(idx); idx = rand.Next(sz); a.Set(idx, false); b.FastClear(idx); idx = rand.Next(sz); a.Set(idx, !a.Get(idx)); b.FastFlip(idx); bool val = b.FlipAndGet(idx); bool val2 = b.FlipAndGet(idx); Assert.IsTrue(val != val2); val = b.GetAndSet(idx); Assert.IsTrue(val2 == val); Assert.IsTrue(b.Get(idx)); if (!val) b.FastClear(idx); Assert.IsTrue(b.Get(idx) == val); } } // test that the various ways of accessing the bits are equivalent DoGet(a, b); // {{dougsale-2.4.0}} // // Java's java.util.BitSet automatically grows as needed - i.e., when a bit is referenced beyond // the size of the BitSet, an exception isn't thrown - rather, the set grows to the size of the // referenced bit. // // System.Collections.BitArray does not have this feature, and thus I've faked it here by // "growing" the array explicitly when necessary (creating a new instance of the appropriate size // and setting the appropriate bits). // // test ranges, including possible extension int fromIndex, toIndex; fromIndex = rand.Next(sz + 80); toIndex = fromIndex + rand.Next((sz >> 1) + 1); // {{dougsale-2.4.0}}: // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSets 'a' // and 'aa' to the same cardinality as 'j+1' when 'a.Count < j+1' and 'fromIndex < toIndex': //BitArray aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j)); // So, if necessary, lets explicitly grow 'a' now; then 'a' and its clone, 'aa', will be of the required size. if (a.Count < toIndex && fromIndex < toIndex) { System.Collections.BitArray tmp = new System.Collections.BitArray(toIndex, false); for (int k = 0; k < a.Count; k++) tmp.Set(k, a.Get(k)); a = tmp; } // {{dougsale-2.4.0}}: now we can invoke this statement without going 'out-of-bounds' System.Collections.BitArray aa = (System.Collections.BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, !a.Get(j)); OpenBitSet bb = (OpenBitSet)b.Clone(); bb.Flip(fromIndex, toIndex); DoIterate(aa, bb, mode); // a problem here is from flip or doIterate fromIndex = rand.Next(sz + 80); toIndex = fromIndex + rand.Next((sz >> 1) + 1); // {{dougsale-2.4.0}}: // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa' // when 'a.Count < j+1' and 'fromIndex < toIndex' //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false); // So, if necessary, lets explicitly grow 'aa' now if (a.Count < toIndex && fromIndex < toIndex) { aa = new System.Collections.BitArray(toIndex); for (int k = 0; k < a.Count; k++) aa.Set(k, a.Get(k)); } else { aa = (System.Collections.BitArray)a.Clone(); } for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false); bb = (OpenBitSet)b.Clone(); bb.Clear(fromIndex, toIndex); DoNextSetBit(aa, bb); // a problem here is from clear() or nextSetBit fromIndex = rand.Next(sz + 80); toIndex = fromIndex + rand.Next((sz >> 1) + 1); // {{dougsale-2.4.0}}: // The following commented-out, compound statement's 'for loop' implicitly grows the Java BitSet 'aa' // when 'a.Count < j+1' and 'fromIndex < toIndex' //aa = (BitArray)a.Clone(); for (int j = fromIndex; j < toIndex; j++) aa.Set(j, false); // So, if necessary, lets explicitly grow 'aa' now if (a.Count < toIndex && fromIndex < toIndex) { aa = new System.Collections.BitArray(toIndex); for (int k = 0; k < a.Count; k++) aa.Set(k, a.Get(k)); } else { aa = (System.Collections.BitArray)a.Clone(); } for (int j = fromIndex; j < toIndex; j++) aa.Set(j, true); bb = (OpenBitSet)b.Clone(); bb.Set(fromIndex, toIndex); DoNextSetBit(aa, bb); // a problem here is from set() or nextSetBit if (a0 != null) { Assert.AreEqual(a.Equals(a0), b.Equals(b0)); Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a), b.Cardinality()); // {{dougsale-2.4.0}} // // The Java code used java.util.BitSet, which grows as needed. // When a bit, outside the dimension of the set is referenced, // the set automatically grows to the necessary size. The // new entries default to false. // // BitArray does not grow automatically and is not growable. // Thus when BitArray instances of mismatched cardinality // interact, we must first explicitly "grow" the smaller one. // // This growth is acheived by creating a new instance of the // required size and copying the appropriate values. // //BitArray a_and = (BitArray)a.Clone(); a_and.And(a0); //BitArray a_or = (BitArray)a.Clone(); a_or.Or(a0); //BitArray a_xor = (BitArray)a.Clone(); a_xor.Xor(a0); //BitArray a_andn = (BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false); System.Collections.BitArray a_and; System.Collections.BitArray a_or; System.Collections.BitArray a_xor; System.Collections.BitArray a_andn; if (a.Count < a0.Count) { // the Java code would have implicitly resized 'a_and', 'a_or', 'a_xor', and 'a_andn' // in this case, so we explicitly create a resized stand-in for 'a' here, allowing for // a to keep its original size while 'a_and', 'a_or', 'a_xor', and 'a_andn' are resized System.Collections.BitArray tmp = new System.Collections.BitArray(a0.Count, false); for (int z = 0; z < a.Count; z++) tmp.Set(z, a.Get(z)); a_and = (System.Collections.BitArray)tmp.Clone(); a_and.And(a0); a_or = (System.Collections.BitArray)tmp.Clone(); a_or.Or(a0); a_xor = (System.Collections.BitArray)tmp.Clone(); a_xor.Xor(a0); a_andn = (System.Collections.BitArray)tmp.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false); } else if (a.Count > a0.Count) { // the Java code would have implicitly resized 'a0' in this case, so // we explicitly do so here: System.Collections.BitArray tmp = new System.Collections.BitArray(a.Count, false); for (int z = 0; z < a0.Count; z++) tmp.Set(z, a0.Get(z)); a0 = tmp; a_and = (System.Collections.BitArray)a.Clone(); a_and.And(a0); a_or = (System.Collections.BitArray)a.Clone(); a_or.Or(a0); a_xor = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0); a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false); } else { // 'a' and 'a0' are the same size, no explicit growing necessary a_and = (System.Collections.BitArray)a.Clone(); a_and.And(a0); a_or = (System.Collections.BitArray)a.Clone(); a_or.Or(a0); a_xor = (System.Collections.BitArray)a.Clone(); a_xor.Xor(a0); a_andn = (System.Collections.BitArray)a.Clone(); for (int j = 0; j < a_andn.Count; j++) if (a0.Get(j)) a_andn.Set(j, false); } OpenBitSet b_and = (OpenBitSet)b.Clone(); Assert.AreEqual(b, b_and); b_and.And(b0); OpenBitSet b_or = (OpenBitSet)b.Clone(); b_or.Or(b0); OpenBitSet b_xor = (OpenBitSet)b.Clone(); b_xor.Xor(b0); OpenBitSet b_andn = (OpenBitSet)b.Clone(); b_andn.AndNot(b0); DoIterate(a_and, b_and, mode); DoIterate(a_or, b_or, mode); DoIterate(a_xor, b_xor, mode); DoIterate(a_andn, b_andn, mode); Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_and), b_and.Cardinality()); Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_or), b_or.Cardinality()); Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_xor), b_xor.Cardinality()); Assert.AreEqual(SupportClass.BitSetSupport.Cardinality(a_andn), b_andn.Cardinality()); // test non-mutating popcounts Assert.AreEqual(b_and.Cardinality(), OpenBitSet.IntersectionCount(b, b0)); Assert.AreEqual(b_or.Cardinality(), OpenBitSet.UnionCount(b, b0)); Assert.AreEqual(b_xor.Cardinality(), OpenBitSet.XorCount(b, b0)); Assert.AreEqual(b_andn.Cardinality(), OpenBitSet.AndNotCount(b, b0)); } a0 = a; b0 = b; } }
public override void ComputeLastPos(RegexpBuilder bld) { LastPos = new BitArray(bld.positions.Count); LastPos.Set(Position, true); }
private Brush getBrush(int resPos, int ledPos) { System.Collections.BitArray bite = new System.Collections.BitArray(8); byte[] bitref = new byte[1]; Brush br; bite.Set(0, led_bits.Get(48 * resPos + 3 * ledPos)); bite.Set(1, led_bits.Get(48 * resPos + 3 * ledPos + 1)); bite.Set(2, led_bits.Get(48 * resPos + 3 * ledPos + 2)); bite.CopyTo(bitref, 0); switch (bitref[0]) { case 1: br = br_blue; break; case 2: br = br_red; break; case 3: br = br_rb; break; case 4: br = br_green; break; case 5: br = br_gb; break; case 6: br = br_rg; break; case 7: br = br_rgb; break; default: br = br_black; break; } return br; }
public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray( (reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64); TermEnum enumerator = (null != lowerTerm && collator == null ? reader.Terms(new Term(fieldName, lowerTerm)) : reader.Terms(new Term(fieldName))); try { if (enumerator.Term() == null) { return bits; } TermDocs termDocs = reader.TermDocs(); try { if (collator != null) { do { Term term = enumerator.Term(); if (term != null && term.Field().Equals(fieldName)) { if ((lowerTerm == null || (includeLower ? collator.Compare(term.Text(), lowerTerm) >= 0 : collator.Compare(term.Text(), lowerTerm) > 0)) && (upperTerm == null || (includeUpper ? collator.Compare(term.Text(), upperTerm) <= 0 : collator.Compare(term.Text(), upperTerm) < 0))) { // term in range, lookup docs termDocs.Seek(enumerator.Term()); while (termDocs.Next()) { bits.Set(termDocs.Doc(), true); } } } } while (enumerator.Next()); } else // null collator; using Unicode code point ordering { bool checkLower = false; if (!includeLower) // make adjustments to set to exclusive checkLower = true; do { Term term = enumerator.Term(); if (term != null && term.Field().Equals(fieldName)) { if (!checkLower || null == lowerTerm || String.CompareOrdinal(term.Text(), lowerTerm) > 0) { checkLower = false; if (upperTerm != null) { int compare = String.CompareOrdinal(upperTerm, term.Text()); /* if beyond the upper term, or is exclusive and * this is equal to the upper term, break out */ if ((compare < 0) || (!includeUpper && compare == 0)) { break; } } /* we have a good term, find the docs */ termDocs.Seek(enumerator.Term()); while (termDocs.Next()) { bits.Set(termDocs.Doc(), true); } } } else { break; } } while (enumerator.Next()); } } finally { termDocs.Close(); } } finally { enumerator.Close(); } return bits; }
public override DocIdSet GetDocIdSet(IndexReader reader) { System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); bits.Set(doc, true); return new DocIdBitSet(bits); }
public virtual int DoTermConjunctions(IndexSearcher s, int termsInIndex, int maxClauses, int iter) { int ret = 0; long nMatches = 0; for (int i = 0; i < iter; i++) { int nClauses = r.Next(maxClauses - 1) + 2; // min 2 clauses BooleanQuery bq = new BooleanQuery(); System.Collections.BitArray termflag = new System.Collections.BitArray((termsInIndex % 64 == 0?termsInIndex / 64:termsInIndex / 64 + 1) * 64); for (int j = 0; j < nClauses; j++) { int tnum; // don't pick same clause twice tnum = r.Next(termsInIndex); if (termflag.Get(tnum)) tnum = BitSetSupport.NextClearBit(termflag, tnum); if (tnum < 0 || tnum >= termsInIndex) tnum = BitSetSupport.NextClearBit(termflag, 0); termflag.Set(tnum, true); Query tq = new TermQuery(terms[tnum]); bq.Add(tq, Occur.MUST); } CountingHitCollector hc = new CountingHitCollector(); s.Search(bq, hc); nMatches += hc.GetCount(); ret += hc.GetSum(); } System.Console.Out.WriteLine("Average number of matches=" + (nMatches / iter)); return ret; }
public override System.Collections.BitArray Bits(IndexReader reader) { System.Collections.BitArray bs = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); bs.Set(docs1.scoreDocs[0].doc, true); return bs; }
public virtual void Test() { PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper(); mapper.SetExpectations("test", tokens.Length, true, true); //Test single position for (int i = 0; i < tokens.Length; i++) { System.String token = tokens[i]; mapper.Map(token, 1, null, thePositions[i]); } System.Collections.IDictionary map = mapper.GetFieldToTerms(); Assert.IsTrue(map != null, "map is null and it shouldn't be"); Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1); System.Collections.IDictionary positions = (System.Collections.IDictionary) map["test"]; Assert.IsTrue(positions != null, "thePositions is null and it shouldn't be"); Assert.IsTrue(positions.Count == numPositions, "thePositions Size: " + positions.Count + " is not: " + numPositions); System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64); for (System.Collections.IEnumerator iterator = new System.Collections.Hashtable(positions).GetEnumerator(); iterator.MoveNext(); ) { System.Collections.DictionaryEntry entry = (System.Collections.DictionaryEntry) iterator.Current; PositionBasedTermVectorMapper.TVPositionInfo info = (PositionBasedTermVectorMapper.TVPositionInfo) entry.Value; Assert.IsTrue(info != null, "info is null and it shouldn't be"); int pos = ((System.Int32) entry.Key); bits.Set(pos, true); Assert.IsTrue(info.GetPosition() == pos, info.GetPosition() + " does not equal: " + pos); Assert.IsTrue(info.GetOffsets() != null, "info.getOffsets() is null and it shouldn't be"); if (pos == 0) { Assert.IsTrue(info.GetTerms().Count == 2, "info.getTerms() Size: " + info.GetTerms().Count + " is not: " + 2); //need a test for multiple terms at one pos Assert.IsTrue(info.GetOffsets().Count == 2, "info.getOffsets() Size: " + info.GetOffsets().Count + " is not: " + 2); } else { Assert.IsTrue(info.GetTerms().Count == 1, "info.getTerms() Size: " + info.GetTerms().Count + " is not: " + 1); //need a test for multiple terms at one pos Assert.IsTrue(info.GetOffsets().Count == 1, "info.getOffsets() Size: " + info.GetOffsets().Count + " is not: " + 1); } } int cardinality = 0; for (int i = 0; i < bits.Count; i++) { if (bits.Get(i)) cardinality++; } Assert.IsTrue(cardinality == numPositions, "Bits are not all on"); }
void ReadingTask() { byte[] tempdata = new byte[data.Length]; while (true) { try { if (RTUDevice!=null && RTUDevice.connected != IsConnected) { IsConnected = RTUDevice.connected; using( SecureDBEntities1 db = new SecureDBEntities1()) { tblPDConfig pdc = db.tblPDConfig.Where(n => n.PDName == this.PDName).FirstOrDefault(); if (pdc != null) { pdc.Comm_state = IsConnected ? 1 : 0; db.SaveChanges(); } db.tblPDAlarmLog.Add(new tblPDAlarmLog() { Timestamp = DateTime.Now, PDItem = "Comm_state", PDName = this.PDName, Status = IsConnected ? 1 : 0 , UserMemo=pdc.Memo}); db.SaveChanges(); } } if (RTUDevice != null && RTUDevice.connected) { lock (lockobj) { RTUDevice.ReadDiscreteInputs(1, 0, 0, 12, ref tempdata); if (tempdata == null) { Console.WriteLine(this.PDName + "讀取資料失敗"); reading_fail_cnt++; continue; } else reading_fail_cnt = 0; if ((tblPDConfig.type ?? 1) == 2) //R11 { for (int i = 0; i < tempdata.Length; i++) tempdata[i] = (byte)(~tempdata[i]); System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]); System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata); baryD.Set(0, baryS.Get(4)); //r0 baryD.Set(1, baryS.Get(5)); //s0 baryD.Set(2, baryS.Get(6)); // t0 baryD.Set(3, baryS.Get(0)); //r1 baryD.Set(4, baryS.Get(1)); //s1 baryD.Set(5, baryS.Get(2)); //t1 baryD.Set(6, baryS.Get(7)); // L0 baryD.Set(7, baryS.Get(8)); // L1 baryD.Set(8, baryS.Get(9)); // L2 baryD.Set(9, baryS.Get(10)); // L3 baryD.Set(10, baryS.Get(11)); // L4 baryD.Set(11, baryS.Get(3)); // cab baryD.CopyTo(tempdata, 0); } else if((tblPDConfig.type ?? 1) == 7) { //for (int i = 0; i < tempdata.Length; i++) // tempdata[i] = (byte)(~tempdata[i]); System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]); System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata); baryD.Set(0, baryS.Get(4)); //r0 baryD.Set(1, baryS.Get(5)); //s0 baryD.Set(2, baryS.Get(6)); // t0 baryD.Set(3, baryS.Get(0)); //r1 baryD.Set(4, baryS.Get(1)); //s1 baryD.Set(5, baryS.Get(2)); //t1 baryD.Set(6, baryS.Get(7)); // L0 baryD.Set(7, baryS.Get(8)); // L1 baryD.Set(8, baryS.Get(9)); // L2 baryD.Set(9, baryS.Get(10)); // L3 baryD.Set(10, baryS.Get(11)); // L4 baryD.Set(11, !baryS.Get(3)); // cab baryD.CopyTo(tempdata, 0); } else if ((tblPDConfig.type ?? 1) == 5) //R13 { for (int i = 0; i < tempdata.Length; i++) tempdata[i] = (byte)(~tempdata[i]); System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]); System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata); baryD.Set(0, baryS.Get(4)); //r0 baryD.Set(1, baryS.Get(5)); //s0 baryD.Set(2, baryS.Get(6)); // t0 baryD.Set(3, baryS.Get(0)); //r1 baryD.Set(4, baryS.Get(1)); //s1 baryD.Set(5, baryS.Get(2)); //t1 baryD.Set(6, baryS.Get(7)); // L0 baryD.Set(7, baryS.Get(8)); // L1 baryD.Set(8, baryS.Get(9)); // L2 baryD.Set(9, baryS.Get(10)); // L3 baryD.Set(10, baryS.Get(11)); // L4 baryD.Set(11, !baryS.Get(3)); // cab baryD.CopyTo(tempdata, 0); } else if ((tblPDConfig.type ?? 1) == 3) //R12 { for (int i = 0; i < tempdata.Length; i++) tempdata[i] = (byte)(~tempdata[i]); System.Collections.BitArray baryD = new System.Collections.BitArray(new byte[2]); System.Collections.BitArray baryS = new System.Collections.BitArray(tempdata); baryD.Set(0, baryS.Get(6)); //r0 baryD.Set(1, baryS.Get(7)); //s0 baryD.Set(2, baryS.Get(8)); // t0 baryD.Set(3, baryS.Get(0)); //r1 baryD.Set(4, baryS.Get(1)); //s1 baryD.Set(5, baryS.Get(2)); //t1 baryD.Set(6, baryS.Get(9)); // L0 baryD.Set(7, baryS.Get(10)); // L1 baryD.Set(8, baryS.Get(11)); // L2 //baryD.Set(9, 0baryS.Get(10)); // L3 //baryD.Set(10,0 baryS.Get(11)); // L4 baryD.Set(11, baryS.Get(3) && baryS.Get(4) && baryS.Get(5)); // cab baryD.CopyTo(tempdata, 0); } else if ((tblPDConfig.type ?? 1) == 4) //R23 T74 { System.Collections.BitArray baryD = new System.Collections.BitArray(tempdata); baryD.Set(11,! baryD.Get(11)); baryD.CopyTo(tempdata, 0); } else if ((tblPDConfig.type ?? 1) == 6) { System.Collections.BitArray bard = new System.Collections.BitArray(tempdata); for (int i = 0; i < 11; i++) bard.Set(i, !bard.Get(i)); bard.CopyTo(tempdata, 0); } // RTUDevice.ReadHoldingRegister((ushort)this.DevID, (byte)255, (ushort)(StartAddress - 1), this.RegisterLength, ref tempdata); if (tempdata != null && tempdata.Length != 0) { CheckDataChange(tempdata); System.Array.Copy(tempdata, data, 2); //for (int i = 0; i < tempdata.Length; i++) //{ // data[i] = tempdata[i]; //} } } } } catch (Exception ex) { Console.WriteLine(this.PDName+","+((tempdata==null)?"突然斷線":ex.Message) + "," + ex.StackTrace); } finally { System.Threading.Thread.Sleep(1000); } } }
public static System.Collections.BitArray StringToBitArray(string str) { System.Collections.BitArray bit = new System.Collections.BitArray(str.Length, false); for (int i = 0; i < str.Length; i++) { switch (str[i]) { case '1': bit.Set(i, true); break; } } return bit; }
public override System.Collections.BitArray Bits(IndexReader r) { System.Collections.BitArray b = new System.Collections.BitArray((r.MaxDoc() % 64 == 0?r.MaxDoc() / 64:r.MaxDoc() / 64 + 1) * 64); for (int i = 0; i < docs.Length; i++) { b.Set(docs[i], true); } return b; }
static void ReceiveTask() { Stream stream=tcp.GetStream(); // int voltage=0; // int data; int voltage = 0, current = 0, mod1, mod2, mod3; int AcFail=0,SmrWarning=0,major=0,minor=0; byte[] data = new byte[32]; //while (true) //{ //if (stream.Length == 32 ) //{ int cks = 0; stream.Read(data, 0, 32); Console.WriteLine("read"); voltage = data[1] + data[2] * 256; current = data[3] + data[4]*256; mod1=data[13]; mod2 = data[14]; mod3 = data[15]; AcFail = ((mod1 >> 6) & 1) ; SmrWarning = ((mod1 >> 5) & 1) ; major = ((mod1 >> 3) & 1) ; minor = ((mod1 >> 4) & 1) ; Console.WriteLine("v:{0} i:{1} mod1={2:X2} mod2={3:X2} mod3={4:X2} major:{5} minor:{6} Acfail:{7} SmrWarning:{8}", voltage, current, mod1, mod2, mod3,major,minor,AcFail,SmrWarning); for (int i = 0; i < 32; i++) { cks+=data[i]; Console.Write("{0:X2} ",data[i]); } cks -= data[31]; Console.WriteLine(); if( (cks&255)!=data[31]) Console.WriteLine("cks error {0:X2}!",cks&255); byte[] retData = new byte[6]; retData[0] = (byte)(voltage / 256); retData[1] = (byte)(voltage % 256); retData[2] = (byte)(current / 256); retData[3] = (byte)(current % 256); retData[4] = 0; System.Collections.BitArray ba = new System.Collections.BitArray(new byte[] { 0 }); // bit 0 1 2 3 // major minor SmrWarning AcFail ba.Set(0, major == 0); ba.Set(1, minor == 0); ba.Set(2, SmrWarning == 0); ba.Set(3, AcFail == 0); ba.CopyTo(retData, 5); //for (int i = 0; i < 8; i++) // stream.ReadByte(); //mod1 = stream.ReadByte(); //mod2 = stream.ReadByte(); //mod3 = stream.ReadByte(); }
public virtual void Test() { PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper(); mapper.SetExpectations("test", tokens.Length, true, true); //Test single position for (int i = 0; i < tokens.Length; i++) { System.String token = tokens[i]; mapper.Map(token, 1, null, thePositions[i]); } Support.Dictionary<String, Support.Dictionary<int, PositionBasedTermVectorMapper.TVPositionInfo>> map = mapper.GetFieldToTerms(); Assert.IsTrue(map != null, "map is null and it shouldn't be"); Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1); Support.Dictionary<int, PositionBasedTermVectorMapper.TVPositionInfo> positions = map["test"]; Assert.IsTrue(positions != null, "thePositions is null and it shouldn't be"); Assert.IsTrue(positions.Count == numPositions, "thePositions Size: " + positions.Count + " is not: " + numPositions); System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64); foreach(KeyValuePair<int, PositionBasedTermVectorMapper.TVPositionInfo> entry in positions) { PositionBasedTermVectorMapper.TVPositionInfo info = entry.Value; Assert.IsTrue(info != null, "info is null and it shouldn't be"); int pos = entry.Key; bits.Set(pos, true); Assert.IsTrue(info.Position == pos, info.Position + " does not equal: " + pos); Assert.IsTrue(info.Offsets != null, "info.getOffsets() is null and it shouldn't be"); if (pos == 0) { Assert.IsTrue(info.Terms.Count == 2, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 2); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 2, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 2); } else { Assert.IsTrue(info.Terms.Count == 1, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 1); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 1, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 1); } } Assert.IsTrue(Support.BitSetSupport.Cardinality(bits) == numPositions, "Bits are not all on"); }
protected override KeyValuePair<VariableReference, object>[] MatchImpl(string text, ICollection<string> requiredVariables, ICollection<string> arrayVariables, ICollection<string> mapVariables) { BitArray requiredPatterns = new BitArray(Variables.Count); List<string> variablePatterns = new List<string>(); for (int i = 0; i < Variables.Count; i++) { VariableReference variable = Variables[i]; if (requiredVariables.Contains(variable.Name)) requiredPatterns.Set(i, true); bool allowReservedSet = Type == UriTemplatePartType.ReservedStringExpansion; variablePatterns.Add(BuildVariablePattern(Variables[i], allowReservedSet, "var" + i, requiredVariables, arrayVariables, mapVariables)); } StringBuilder matchPattern = new StringBuilder(); matchPattern.Append("^"); AppendOneOrMoreToEnd(matchPattern, requiredPatterns, variablePatterns, 0); matchPattern.Append("$"); Match match = Regex.Match(text, matchPattern.ToString()); List<KeyValuePair<VariableReference, object>> results = new List<KeyValuePair<VariableReference, object>>(); for (int i = 0; i < Variables.Count; i++) { Group group = match.Groups["var" + i]; if (!group.Success || group.Captures.Count == 0) continue; if (Variables[i].Prefix != null) { if (group.Success && group.Captures.Count == 1) { results.Add(new KeyValuePair<VariableReference, object>(Variables[i], DecodeCharacters(group.Captures[0].Value))); } continue; } bool treatAsArray = arrayVariables.Contains(Variables[i].Name); bool treatAsMap = mapVariables.Contains(Variables[i].Name); bool considerString = !Variables[i].Composite && !treatAsArray && !treatAsMap; bool considerArray = treatAsArray || !treatAsMap; bool considerMap = treatAsMap || !treatAsArray; // first check for a map Group mapKeys = match.Groups["var" + i + "key"]; if (mapKeys.Success && mapKeys.Captures.Count > 0) { Debug.Assert(considerMap, "considerMap"); Group mapValues = match.Groups["var" + i + "value"]; Dictionary<string, string> map = new Dictionary<string, string>(); for (int j = 0; j < mapKeys.Captures.Count; j++) map.Add(DecodeCharacters(mapKeys.Captures[j].Value), DecodeCharacters(mapValues.Captures[j].Value)); results.Add(new KeyValuePair<VariableReference, object>(Variables[i], map)); continue; } // next try an array if (!considerString || group.Captures.Count > 1) { Debug.Assert(considerArray, "considerArray"); List<string> list = new List<string>(group.Captures.Count); foreach (Capture capture in group.Captures) list.Add(DecodeCharacters(capture.Value)); results.Add(new KeyValuePair<VariableReference, object>(Variables[i], list)); continue; } Debug.Assert(considerString, "considerString"); results.Add(new KeyValuePair<VariableReference, object>(Variables[i], DecodeCharacters(group.Captures[0].Value))); } return results.ToArray(); }