public PartialFile(string path, int targetSize) { this.path = path; if (File.Exists(path)) { isCompleted = true; if (targetSize != -1 && new FileInfo(path).Length != targetSize) { throw new ApplicationException("Attempting to initialize the size with an invalid size"); } stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read); } else if (File.Exists(PartialFileName)) { stream = File.Open(PartialFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); ReadBitmapInfo(); } else { if (targetSize == -1) targetSize = DEFAULT_SIZE; var chunks = targetSize / CHUNK_SIZE; if (targetSize % CHUNK_SIZE > 0) chunks++; completedChunks = new System.Collections.BitArray(chunks, false); stream = File.Open(PartialFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None); WriteBitmapInfo(); } }
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(")"); }
public override System.Collections.BitArray Bits(IndexReader reader) { if (cache == null) { cache = new System.Collections.Hashtable(); } lock (cache.SyncRoot) { // check cache System.Collections.BitArray cached = (System.Collections.BitArray) cache[reader]; if (cached != null) { return cached; } } System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); new IndexSearcher(reader).Search(query, new AnonymousClassHitCollector(bits, this)); lock (cache.SyncRoot) { // update cache cache[reader] = bits; } return bits; }
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 RGS_HW_StatusDesc(string devName,byte[] hw_status, byte[] diff) { ArrayhwStatus = new System.Collections.BitArray(hw_status); this.diff = diff; this.devName = devName; this.m_status = hw_status; }
public static bool[,] Rasterize(Point[] points, int width, int height) { Contract.Requires(points != null); Contract.Requires(width > 0); Contract.Requires(height > 0); Contract.Requires(width % 8 == 0); Contract.Ensures(Contract.Result<bool[,]>() != null); Contract.Ensures(Contract.Result<bool[,]>().GetLength(0) == width); Contract.Ensures(Contract.Result<bool[,]>().GetLength(1) == height); var canvas = new Canvas { Background = Brushes.White, Width = width, Height = height }; var polygon = new Polygon { Stroke = Brushes.Black, Fill = Brushes.Black, StrokeThickness = 1, Points = new PointCollection(points) }; canvas.Children.Add(polygon); RenderOptions.SetEdgeMode(canvas, EdgeMode.Aliased); canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, canvas.DesiredSize.Width, canvas.DesiredSize.Height)); var rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default); rtb.Render(canvas); var fmb = new FormatConvertedBitmap(rtb, PixelFormats.BlackWhite, null, 0); var pixels = new byte[width * height / 8]; fmb.CopyPixels(pixels, width / 8, 0); System.Collections.BitArray ba = new System.Collections.BitArray(pixels); var result = new bool[width, height]; for (int i = 0, y = 0; y < height; ++y) for (int x = 0; x < width; ++x, ++i) result[x, y] = !ba[i]; return result; }
public static IList<int> FindPrimes(int max) { //Initialize list to capacity using Legendre's constant to minimize copying lists as bounds are exceeded var vals = new List<int>((int)(max / (Math.Log(max) - 1.08366))); var maxSquareRoot = Math.Sqrt(max); //Use a BitArray for light-weight collection of numbers already elminated as not prime. var eliminated = new System.Collections.BitArray(max + 1); //2 is the only even prime, add it here and skip evaluating all even numbers below vals.Add(2); for (int i = 3; i <= max; i += 2) { if (!eliminated[i]) { //We only need to evaluate up to sqrt (any non-primes beyond will already be eliminated as a multiple) if (i < maxSquareRoot) { //Eliminate all multiples i (after i squared, lower multiple are already eliminated) for (int j = i * i; j <= max; j += 2 * i) eliminated[j] = true; } //Add number to primes if it hasn't been eliminated vals.Add(i); } } return vals; }
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); new IndexSearcher(reader).Search(query, new AnonymousClassHitCollector(bits, this)); return bits; }
public WD_HW_StatusDesc(string devName,byte[] status, byte[] diff) { ArrayhwStatus = new System.Collections.BitArray(status); this.diff = diff; this.devName = devName; m_status = status; }
public Bloom(int elements, double falsePositiveRate) { var size = (int)(-elements * Math.Log(falsePositiveRate) / Math.Pow(Math.Log(2), 2)) / 8; HashFunctions = (int)(size * 8 / elements * Math.Log(2)); Bits = new System.Collections.BitArray(size * 8); }
/// <summary>Constructor</summary> public Result(bool best, BitArray bestHandBits, PokerHand bestHand, PokerHand selectedHand) { _best = best; _bestHandBits = bestHandBits; _bestHand = bestHand; _selectedHand = selectedHand; }
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; }
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 BitArray ToOpenTK(this Keys buttons) { BitArray result = new BitArray((int)Key.LastKey + 1, false); int k; if (mapToOpenTK.TryGetValue((int)(buttons & ~Keys.Modifiers), out k)) result[k] = true; return result; }
public ThreadPlaySound(int recordid, int cnt, System.Collections.BitArray Status, TouchPanelManager touch_panel_mgr,Controller controller) { this.recordid = recordid; this.cnt = cnt; this.Status = Status; this.touch_panel_mgr = touch_panel_mgr; this.controller = controller; }
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; }
public System.Collections.IEnumerable getEnum() { System.Collections.BitArray aryInx = new System.Collections.BitArray(diff); for (int i = 0; i < aryInx.Count; i++) { if (aryInx.Get(i)) yield return (RGS_HW_Status_Bit_Enum)i; } }
//取得所有錯誤訊息的位元咧舉值 public System.Collections.IEnumerable getEnum(byte[] indexs) { // throw new Exception("The method or operation is not implemented."); System.Collections.BitArray aryInx = new System.Collections.BitArray(indexs); for (int i = 0; i < aryInx.Count; i++) { if (aryInx.Get(i)) yield return (RGS_HW_Status_Bit_Enum)i; } }
public void Resolution_GoodWeather() { System.Collections.BitArray bits128 = new System.Collections.BitArray(128, true); var res = Bazcrypt.ResolutionArraySolver.CreateResolutionArray(bits128, 8); var unres = Bazcrypt.ResolutionArraySolver.UndoResolutionArray(res); Assert.Equal(16, res.Length); Assert.Equal(bits128.Length, unres.Length); Assert.Equal(bits128, unres); }
internal virtual void DoGet(System.Collections.BitArray a, OpenBitSet b) { int max = a.Count; for (int i = 0; i < max; i++) { if (a.Get(i) != b.Get(i)) { Assert.Fail("mismatch: BitSet=[" + i + "]=" + a.Get(i)); } } }
private static bool Contains(List <System.Collections.BitArray> bitArrays, System.Collections.BitArray bitArray) { foreach (System.Collections.BitArray bitArray2 in bitArrays) { if (Equals(bitArray, bitArray2)) { return(true); } } return(false); }
/// <summary> /// Returns the index of the first bit that is set to true that occurs /// on or after the specified starting index. If no such bit exists /// then -1 is returned. /// </summary> /// <param name="bits">The BitArray object.</param> /// <param name="fromIndex">The index to start checking from (inclusive).</param> /// <returns>The index of the next set bit.</returns> public static int NextSetBit(System.Collections.BitArray bits, int fromIndex) { for (int i = fromIndex; i < bits.Length; i++) { if (bits[i] == true) { return(i); } } return(-1); }
/// <summary> /// Receives an integer value and position as parameter and returns the /// specified bit in that position. /// </summary> /// <param name="tnExpression"></param> /// <param name="tnPosition"></param> /// <returns></returns> public static bool BitTest(int tnExpression, int tnPosition) { //Create an array of integer int[] aInt = { 5 }; //Create the BitArray so the bits are populated System.Collections.BitArray ba = new System.Collections.BitArray(aInt); //Return the appropriate position return(ba[0]); }
private int nextSetBit(System.Collections.BitArray array, int from) { for (int i = from; i < array.Count; i++) { if (array[i]) { return(i); } } return(-1); }
private bool isEmpty(System.Collections.BitArray array) { for (int i = 0; i < array.Count; i++) { if (array[i]) { return(false); } } return(true); }
/// <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); }
/// <summary> Converts a RGraph bitset (set of RNode) /// to a list of RMap that represents the /// mapping between to substructures in G1 and G2 /// (the projection of the RGraph bitset on G1 /// and G2). /// /// </summary> /// <param name="set"> the BitSet /// </param> /// <returns> the RMap list /// </returns> public virtual System.Collections.IList bitSetToRMap(System.Collections.BitArray set_Renamed) { System.Collections.IList rMapList = new System.Collections.ArrayList(); for (int x = nextSetBit(set_Renamed, 0); x >= 0; x = nextSetBit(set_Renamed, x + 1)) { RNode xNode = (RNode)graph[x]; rMapList.Add(xNode.rMap); } return(rMapList); }
} // Close private void Clean() { if (_storage != null) { _storage = null; } if (_receivedSegments != null) { _receivedSegments = null; } } // Clean
public static BitArray ToDuality(this Keys buttons) { BitArray result = new BitArray((int)Key.Last + 1, false); int k; if (mapToDuality.TryGetValue((int)(buttons & ~Keys.Modifiers), out k)) { result[k] = true; } return(result); }
private State FindState(List <State> dStates, BitArray state) { foreach (State s in dStates) { if (IsEqualSet(s.Positions, state)) { return(s); } } return(null); }
public bool IsEmptySet(BitArray b) { for (int i = 0; i != b.Length; ++i) { if (b.Get(i)) { return(false); } } return(true); }
// test interleaving different OpenBitSetIterator.next()/skipTo() internal virtual void DoIterate(System.Collections.BitArray a, OpenBitSet b, int mode) { if (mode == 1) { DoIterate1(a, b); } if (mode == 2) { DoIterate2(a, b); } }
internal virtual void DoNextSetBit(System.Collections.BitArray a, OpenBitSet b) { int aa = -1, bb = -1; do { aa = BitSetSupport.NextSetBit(a, aa + 1); bb = b.NextSetBit(bb + 1); Assert.AreEqual(aa, bb); }while (aa >= 0); }
private UInt16 getUInt16FromBitArray(System.Collections.BitArray bitArray) { if (bitArray.Length > 16) { throw new ArgumentException("Argument length shall be at most 32 bits."); } int[] array = new int[1]; bitArray.CopyTo(array, 0); return((UInt16)array[0]); }
public static void ReverseBitsOrder(System.Collections.BitArray bits, int begin, int end) { bool bit; while (begin < end) { bit = bits[end]; bits[end--] = bits[begin]; bits[begin++] = bit; } }
private static byte[] EncryptSafe(byte[] bytes, int key) { Random rand = new Random(key); byte[] k = new byte[bytes.Length]; rand.NextBytes(k); System.Collections.BitArray arr = new System.Collections.BitArray(bytes); arr.Xor(new System.Collections.BitArray(k)); arr.CopyTo(k, 0); return(k); }
public static void Reverse(this System.Collections.BitArray instance) { int length = instance.Length; int mid = (length / 2); for (int i = 0; i < mid; i++) { bool bit = instance[i]; instance[i] = instance[length - i - 1]; instance[length - i - 1] = bit; } }
public static string ByteToBitToString(byte[] array) { System.Collections.BitArray bits = new System.Collections.BitArray(array); string s = null; for (int i = 0; i < bits.Count; i++) { char c = bits[i] ? '1' : '0'; s += c; } return(s); }
/// <summary> /// check if any bit is ON. /// </summary> public static bool Any(this System.Collections.BitArray self) { foreach (bool bit in self) { if (bit) { return(true); } } return(false); }
public static void Guild_ListPlayersInfo(List <Global.guild_player> guildMembers, PacketWriter Writer) { Writer.Byte(guildMembers.Count); foreach (Global.guild_player m in guildMembers) { Writer.DWord(m.MemberID); Writer.Text(m.Name); Writer.Byte(m.Rank); Writer.Byte(m.Level); Writer.DWord(m.DonateGP); System.Collections.BitArray bits = new System.Collections.BitArray(new bool[] { m.noticeeditRight, m.guildstorageRight, m.unionRight, m.withdrawRight, m.joinRight, false, false, false }); byte[] bytes = new byte[1]; bits.CopyTo(bytes, 0); Writer.DWord((int)bytes[0]); Writer.DWord(0); Writer.DWord(0); Writer.DWord(0); if (m.GrantName != null) { if (m.GrantName != "") { Writer.Text(m.GrantName); } else { Writer.Word(0); } } else { Writer.Word(0); } Writer.DWord(m.Model); Writer.Byte(m.FWrank); Writer.Byte(m.Xsector); Writer.Byte(m.Ysector); Writer.DWord(0xFFFFFFFF); // when he entered last time 25794314 Writer.DWord(0x0189EECA); // when he leveled up last time 25816778 later :P Writer.Bool(!m.Online); } }
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; }
/// <summary> Projects a RGraph bitset on the source graph G2.</summary> /// <param name="set"> RGraph BitSet to project /// </param> /// <returns> The associate BitSet in G2 /// </returns> public virtual System.Collections.BitArray projectG2(System.Collections.BitArray set_Renamed) { System.Collections.BitArray projection = new System.Collections.BitArray((secondGraphSize % 64 == 0 ? secondGraphSize / 64 : secondGraphSize / 64 + 1) * 64); RNode xNode = null; for (int x = nextSetBit(set_Renamed, 0); x >= 0; x = nextSetBit(set_Renamed, x + 1)) { xNode = (RNode)graph[x]; SupportClass.BitArraySupport.Set(projection, xNode.rMap.id2); } return(projection); }
public void SrchDlg_Foo() { var arr = new System.Collections.BitArray(60); arr[14] = true; int i = 0; foreach (bool x in arr) { if (x) System.Diagnostics.Debug.Print("X: {0}", i); ++i; } }
/// <summary> Create a SortedVIntList from a BitSet.</summary> /// <param name="bits"> A bit set representing a set of integers. /// </param> public SortedVIntList(System.Collections.BitArray bits) { SortedVIntListBuilder builder = new SortedVIntListBuilder(this); int nextInt = SupportClass.BitSetSupport.NextSetBit(bits, 0); while (nextInt != -1) { builder.AddInt(nextInt); nextInt = SupportClass.BitSetSupport.NextSetBit(bits, nextInt + 1); } builder.Done(); }
public System.Collections.BitArray bitToString(byte arr) { System.Collections.BitArray myBA = new System.Collections.BitArray(8); byte bb = (byte)0x01; for (int i = 0; i < 8; i++) { myBA[i] = (byte)(arr & bb) == bb; bb <<= 1; } return(myBA); }
public override object ReadValue(Type ValueType, Newtonsoft.Json.JsonReader Reader, MudObject Owner) { var value = Reader.Value.ToString(); var r = new System.Collections.BitArray(value.Length); for (int i = 0; i < value.Length; ++i) { r[i] = (value[i] == '1'); } Reader.Read(); return(r); }
internal virtual void DoIterate2(System.Collections.BitArray a, OpenBitSet b) { int aa = -1, bb = -1; OpenBitSetIterator iterator = new OpenBitSetIterator(b); do { aa = BitSetSupport.NextSetBit(a, aa + 1); bb = rand.NextDouble() > 0.5 ? iterator.NextDoc(null) : iterator.Advance(bb + 1, null); Assert.AreEqual(aa == -1?DocIdSetIterator.NO_MORE_DOCS:aa, bb); }while (aa >= 0); }
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> /// Returns the number of bits set to true in this BitSet. /// </summary> /// <param name="bits">The BitArray object.</param> /// <returns>The number of bits set to true in this BitSet.</returns> public static int Cardinality(System.Collections.BitArray bits) { int count = 0; for (int i = 0; i < bits.Length; i++) { if (bits[i]) { count++; } } return(count); }
public static string ToBitString(byte[] buffer) { var bits = new System.Collections.BitArray(buffer); var sb = new System.Text.StringBuilder(); for (int i = 0; i < bits.Count; i++) { char c = bits[i] ? '1' : '0'; sb.Append(c); } return(sb.ToString()); }
public static System.Collections.BitArray ToBits(byte var) { System.Collections.BitArray F = new System.Collections.BitArray(8); F[0] = (bool)(((byte)var & (1 << 7)) != 0); F[1] = (bool)(((byte)var & (1 << 6)) != 0); F[2] = (bool)(((byte)var & (1 << 5)) != 0); F[3] = (bool)(((byte)var & (1 << 4)) != 0); F[4] = (bool)(((byte)var & (1 << 3)) != 0); F[5] = (bool)(((byte)var & (1 << 2)) != 0); F[6] = (bool)(((byte)var & (1 << 1)) != 0); F[7] = (bool)(((byte)var & (1 << 0)) != 0); return(F); }
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); } }
/// <summary> Returns a BitSet with true for documents which should be /// permitted in search results, and false for those that should /// not. /// </summary> /// <deprecated> Use {@link #GetDocIdSet(IndexReader)} instead. /// </deprecated> //@Override public override System.Collections.BitArray Bits(IndexReader reader) { TermEnum enumerator = query.GetEnum(reader); try { System.Collections.BitArray bitSet = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64); new AnonymousClassTermGenerator(bitSet, this).Generate(query, reader, enumerator); return bitSet; } finally { enumerator.Close(); } }
private int varId; // Unique Id of next variable #endregion Fields #region Constructors /// <summary> /// Creaes a Fuzzy Rule Base /// </summary> /// <param name="vsName">Name of the Rule Base</param> public FuzzyRuleBase(string vsName) { mdAlphaCut = Constants.FuzzyAlphaCutDefault; meCorrelationMethod = EnumFuzzyCorrelationMethod.Product; meDefuzzifyMethod = EnumFuzzyDefuzzifyMethod.Centroid; meInferenceMethod = EnumFuzzyInferenceMethod.Add; varId = Constants.FuzzyVarIdInitial; moVariableList = new Dictionary<string, FuzzyRuleVariable>(); ruleId = Constants.FuzzyRuleIdInitial; moRuleList = new List<FuzzyRule>(10); moCndRuleList = new List<FuzzyRule>(10); moUncRuleList = new List<FuzzyRule>(10); moFbInitial = new System.Collections.BitArray(Constants.FUZZY_MAXVALUES); msName = vsName; }
// From http://www.daimi.au.dk/~ivan/FastExpproject.pdf // Left to Right Binary Exponentiation public static decimal Pow(decimal x, uint y) { decimal A = 1m; System.Collections.BitArray e = new System.Collections.BitArray(BitConverter.GetBytes(y)); int t = e.Count; for (int i = t - 1; i >= 0; --i) { A *= A; if (e[i] == true) { A *= x; } } return A; }
public virtual IEnumerable<Substate> GetAdmissibleSubstates([NotNull] State state, [NotNull] SubstateCombinationSet substateCombinationSet) { Assert.ArgumentNotNull(state, "state"); Assert.ArgumentNotNull(substateCombinationSet, "substateCombinationSet"); if (!substateCombinationSet.SubstateCombinations.Any()) { return state.Substates; } System.Collections.BitArray flags = new System.Collections.BitArray(state.Substates.Count); int index = 0; foreach (Substate substate in state.Substates) { flags[index] = substate.Active; ++index; } foreach (IDictionary<string, bool> substateCombination in substateCombinationSet.SubstateCombinations) { bool flag = state.Substates.Aggregate( true, (current, substate) => current && ((!substate.Active) || substateCombination[substate.Code])); index = 0; foreach (Substate substate in state.Substates) { flags[index] = flags[index] || (flag && substateCombination[substate.Code]); ++index; } } LinkedList<Substate> result = new LinkedList<Substate>(); index = 0; foreach (Substate substate in state.Substates) { if (flags[index]) { result.AddLast(substate); } ++index; } return result; }
public 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[location] = true; received[location] = random.Next(929); } } }
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 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 static IList<int> FindPrimes(int max) { var vals = new List<int>((int)(max / (Math.Log(max) - 1.08366))); var maxSquareRoot = Math.Sqrt(max); var eliminated = new System.Collections.BitArray(max + 1); vals.Add(2); for (int i = 3; i <= max; i += 2) { if (!eliminated[i]) { if (i < maxSquareRoot) { for (int j = i * i; j <= max; j += 2 * i) eliminated[j] = true; } vals.Add(i); } } return vals; }