本文整理汇总了C#中System.Collections.BitArray.Get方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.BitArray.Get方法的具体用法?C# System.Collections.BitArray.Get怎么用?C# System.Collections.BitArray.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了System.Collections.BitArray.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getEnum
public System.Collections.IEnumerable getEnum(byte[] indexs)
{
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;
}
}
示例2: IOTask
void IOTask()
{
byte[] m_status=new byte[2];
int cnt=0;
// bool IsSucess;
while (true)
{
if (IOCard != null)
{
lock (IOCard)
{
if (IOCard.GetPlayStatus(1, out m_status[0], out m_status[1], out cnt))
{
System.Collections.BitArray ary = new System.Collections.BitArray(m_status);
Status.Set((int)StatusIndex.AC, ary.Get((int)StatusIndex.AC));
Status.Set((int)StatusIndex.DC, ary.Get((int)StatusIndex.DC));
Status.Set((int)StatusIndex.AMP, ary.Get((int)StatusIndex.AMP));
//Status.Set((int)StatusIndex.BUSY, ary.Get((int)StatusIndex.BUSY));
Status.Set((int)StatusIndex.Door, ary.Get((int)StatusIndex.Door));
if (m_status[1] > SpeakerOut)
SpeakerOut = m_status[1];
// Status.Set((int)StatusIndex.SPEAKER, ary.Get((int)StatusIndex.SPEAKER));
}
}
Console.WriteLine("擴大機輸出讀值:{0:X2}", m_status[1]);
}
System.Threading.Thread.Sleep(1000);
}
}
示例3: IsEqualSet
public bool IsEqualSet(BitArray s1, BitArray s2)
{
int i;
for (i = 0; i < s1.Length && i < s2.Length; ++i)
{
if (s1.Get(i) != s2.Get(i))
return false;
}
for (; i < s1.Length; ++i)
{
if (s1.Get(i))
return false;
}
for (; i < s2.Length; ++i)
{
if (s2.Get(i))
return false;
}
return true;
}
示例4: DumpSet
public static string DumpSet(BitArray ba)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
for (int i = 0; i < ba.Length; ++i)
{
if (ba.Get(i))
{
sb.Append(' ');
sb.Append(i);
}
}
sb.Append(" }");
return sb.ToString();
}
示例5: AppendZeroOrMoreToEnd
private static void AppendZeroOrMoreToEnd(StringBuilder pattern, BitArray requiredPatterns, List<string> patterns, int startIndex)
{
if (startIndex < 0)
throw new ArgumentOutOfRangeException("startIndex cannot be negative", "startIndex");
if (startIndex >= patterns.Count)
throw new ArgumentException("startIndex cannot be greater than the number of patterns.", "startIndex");
for (int i = startIndex; i < patterns.Count; i++)
{
pattern.Append(@"(?:\.").Append(patterns[i]).Append(")");
if (!requiredPatterns.Get(i))
pattern.Append('?');
}
}
示例6: Test
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");
}
示例7: NodeId
/// <summary>
/// Implements the operator >>,
/// </summary>
/// <param name="a">A.</param>
/// <param name="shift">The shift.</param>
/// <returns>The result of the operator.</returns>
public static NodeId operator >>(NodeId a, int shift)
{
if (((object)a == null) || shift == 0)
{
return a;
}
System.Collections.BitArray input = new System.Collections.BitArray(a.Data);
System.Collections.BitArray resultarray = new System.Collections.BitArray(a.Digits * 8);
byte[] result = new byte[a.Digits];
for (int i = a.Digits * 8 - 1; i >= a.Digits * 8 - 1 - shift; i--)
{
resultarray[i] = false;
}
for (int i = a.Digits * 8 - 1 - shift; i >= 0; i--)
{
resultarray.Set(i, input.Get(i + shift));
}
resultarray.CopyTo(result, 0);
Array.Reverse(result);
return new NodeId(result);
}
示例8: DoRandomSets
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);
//.........这里部分代码省略.........
示例9: AppendOneOrMoreToEnd
private static void AppendOneOrMoreToEnd(StringBuilder pattern, BitArray requiredPatterns, List<string> patterns, int startIndex)
{
if (startIndex < 0)
throw new ArgumentOutOfRangeException("startIndex cannot be negative", "startIndex");
if (startIndex >= patterns.Count)
throw new ArgumentException("startIndex cannot be greater than the number of patterns.", "startIndex");
pattern.Append("(?:");
if (requiredPatterns.Get(startIndex))
{
// include the required first item
pattern.Append(patterns[startIndex]);
if (startIndex < patterns.Count - 1)
{
// optionally include at least one more from there to the end
pattern.Append("(?:,");
AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
pattern.Append(")?");
}
}
else
{
if (startIndex < patterns.Count - 1)
{
// include the first item and at least one more from there to the end
pattern.Append(patterns[startIndex]).Append(",");
AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
pattern.Append("|");
}
// include the first item alone
pattern.Append(patterns[startIndex]);
if (startIndex < patterns.Count - 1)
{
// don't include the first item, but do include one or more to the end
pattern.Append("|");
AppendOneOrMoreToEnd(pattern, requiredPatterns, patterns, startIndex + 1);
}
}
pattern.Append(")");
}
示例10: DoTermConjunctions
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;
}
示例11: TableEntry
/// <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);
}
示例12: findCostTo
//.........这里部分代码省略.........
(
game.playerList[ player ].foreignRelation[ game.grid[ x, y ].territory - 1 ].politic == (byte)Form1.relationPolType.war &&
attack
)
)
) &&
!caseOccupiedByRelationType( x, y, player, pols )
)
{
pnt1[ pos ] = new Point( x, y );
pos ++;
}
}
Point[] pnt = new Point[ pos ];
int[] cost = new int[ pos ], prevPnt = new int[ pos ], order = new int[ pos ];
System.Collections.BitArray[] inRange = new System.Collections.BitArray[ pos ];
for ( int i = 0; i < pos; i ++ )
{
pnt[ i ] = pnt1[ i ];
order[ i ] = -1;
inRange[ i ] = new System.Collections.BitArray( i );
}
System.Collections.BitArray alreadyWorked = new System.Collections.BitArray( pos, false );
order[ indOri ] = 0;
cost[ indOri ] = 0;
bool mod = true, modInRad = false;
for ( int rad = 0; mod && rad < 3 * game.width; rad ++ )
{
mod = false;
modInRad = true;
while ( modInRad )
{
modInRad = false;
for ( int i = 0; i < pos; i ++ )
if ( order[ i ] == rad )
{
if ( !alreadyWorked.Get( i ) )
{
for ( int j = 0; j < pos; j ++ )
if ( isNextTo( pnt[ i ], pnt[ j ] ) )
{
if ( i < j )
inRange[ j ].Set( i, true );
else if ( i > j )
inRange[ i ].Set(j, true );
}
alreadyWorked.Set( i, true );
}
for ( int j = 0; j < pos; j ++ )
if (
(
(
i < j &&
inRange[ j ].Get( i )
) ||
(
i > j &&
inRange[ i ].Get( j )
)
)
&&
(
order[ j ] == -1 ||
(
order[ j ] > rad &&
order[ j ] > rad + costBetween( pnt[ i ], pnt[ j ] )
)
)
)
{
order[ i ] --;
order[ j ] = rad + costBetween( pnt[ i ], pnt[ j ] );
prevPnt[ j ] = i;
mod = true;
modInRad = true;
if ( j == indDest )
return order[ j ];
}
}
else if ( order[ i ] > rad )
{
mod = true;
}
}
}
return 10000;
}
示例13: findWayTo4
//.........这里部分代码省略.........
}
}
Point[] pnt = new Point[ pos ];
int[] cost = new int[ pos ], prevPnt = new int[ pos ], order = new int[ pos ];
Int16[][] inRange = new Int16[ pos ][];
for ( int i = 0; i < pos; i ++ )
{
pnt[ i ] = pnt1[ i ];
order[ i ] = -1;
}
System.Collections.BitArray alreadyWorked = new System.Collections.BitArray( pos, false );
order[ indOri ] = 0;
cost[ indOri ] = 0;
Point[] way;
bool mod = true, modInRad = false;
for ( int rad = 0; mod; rad ++ )
{
mod = false;
modInRad = true;
while ( modInRad )
{
modInRad = false;
for ( int i = 0; i < pos; i ++ )
if ( order[ i ] == rad )
{
if ( !alreadyWorked.Get( i ) )
{
Int16[] temp = new Int16[ pos ];
int tot = 0;
for ( int j = 0; j < pos; j ++ )
if ( isNextTo( pnt[ i ], pnt[ j ] ) )
{
temp[ tot ] = (Int16)j;
tot ++;
}
inRange[ i ] = new Int16[ tot ];
for ( int j = 0; j < tot; j ++ )
inRange[ i ][ j ] = temp[ j ];
alreadyWorked.Set( i, true );
}
for ( int j = 0; j < inRange[ i ].Length; j ++ )
if (
order[ inRange[ i ][ j ] ] == -1 ||
(
order[ inRange[ i ][ j ] ] > rad &&
order[ inRange[ i ][ j ] ] > rad + costBetween( pnt[ i ], pnt[ inRange[ i ][ j ] ] )
)
)
{
order[ i ] --;
order[ inRange[ i ][ j ] ] = rad + costBetween( pnt[ i ], pnt[ inRange[ i ][ j ] ] );
prevPnt[ inRange[ i ][ j ] ] = i;
mod = true;
示例14: DirtyJob
private void DirtyJob()
{
VentsTools VT = new VentsTools();
bool refreshValues = false;
if (VT.ReadConfigFromDB(VentsConst.connectionString, VentsConst._CONFtb, ref _ventsData))
if (ReadDataFromPLC())
{
//проверим нет ли значений превышающих _MAX_ENERGY_COUNTER (*100 квтч), если есть - добавим число к общему значению счетчика (ventEnergyConf.tb 'countvalue')
//также проверим нет ли нулевых значений (что может означать неисправность, например "нет связи")
//если есть ноль, проверим сообщение об ошибке, и если есть ошибка заменим значение на -1
foreach(Vents record in _ventsData)
{
if (record.value >= VentsConst._MAX_ENERGY_COUNTER)
{
#region лямбда
ventdel vd = (DB, start, size) =>
{
string RDY_REF_state = "";
try
{
if (_client.ConnectTo(VentsConst._ipPLC, VentsConst._RACK, VentsConst._SLOT) != 0)
throw new Exception("Cant connect to PLC");
int result;
byte[] buffer = new byte[1];
System.Collections.BitArray ba;
result = _client.DBRead(DB, start+1, size, buffer); //vent.startBit+1,- secont byte of Input Stateword (RDY_REF bit is a 3rd bit)
if (result != 0)
ShowError(result);
else
{
_client.Disconnect();
ba = new System.Collections.BitArray(new byte[] { buffer[0] });
return ba.Get(2) ? RDY_REF_state = "Ebabled" : RDY_REF_state = "Disabled";
}
return RDY_REF_state;
}
catch (Exception ex)
{
_log.Error(ex.Message);
return RDY_REF_state;
}
};
#endregion
//обновим значение счетчика в БД, перед этим проверим не включен ли вентилятор
if (vd(record.DB, record.startBit, 1) == "Disabled")
{
if (VT.UpdateCountValuesConfTB(record))
//сбросим счетчик на частотном преобразователе
if (SendResetBitToPLC(record.resetM))
{
refreshValues = true;
Thread.Sleep(1000);
}
}
}
if(record.value == 0)
{
}
}
//если обнаружено превышение счетчика, то не будем записывать считанные данные, а подождем немного и выполним "грязную работу" еще раз
if (refreshValues)
{
Thread.Sleep(1000);
new Thread(DirtyJob).Start();
}
else
{
//сохраним значения в БД, если за этот час не было записей
int LRCHres = VT.LastRecordCurrentHour(System.DateTime.Now);
if(LRCHres== 0 )
VT.WriteDataToDB(_ventsData);
else if (_debugBit)
VT.WriteDataToDB(_ventsData);
}
}
}
示例15: IsEmptySet
public bool IsEmptySet(BitArray b)
{
for (int i = 0; i != b.Length; ++i)
{
if (b.Get(i))
return false;
}
return true;
}