本文整理汇总了C#中System.Collections.BitArray.Or方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Or方法的具体用法?C# BitArray.Or怎么用?C# BitArray.Or使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了BitArray.Or方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//input
int arraySize = int.Parse(Console.ReadLine());
//get array
int[] toSearch = new int[arraySize];
for (int i = 0; i < arraySize; i++)
{
toSearch[i] = int.Parse(Console.ReadLine());
}
// variables
BitArray sumFlags = new BitArray(arraySize);
BitArray maxFlags = new BitArray(arraySize);
int curSum = 0;
int maxSum = toSearch.Sum();
for (int curNumb = 0; curNumb < toSearch.Length; curNumb++)
{
// Step 1: Get Current Sum
curSum += toSearch[curNumb];
sumFlags.Set(curNumb, true);
if (curSum > maxSum)
{
// Store the Sum
maxSum = curSum;
// Flag the indexes
maxFlags.SetAll(false);
maxFlags.Or(sumFlags);
}
else
{
if (curSum < 0)
{
// discard and start summing again
curSum = 0;
sumFlags.SetAll(false);
}
else
{
// keep going
continue;
}
}
}
// output
Console.WriteLine(maxSum);
}
示例2: UseSwitch
// use a switch if more than 5 alternatives and none starts with a resolver
bool UseSwitch (Node p) {
BitArray s1, s2;
if (p.typ != Node.alt) return false;
int nAlts = 0;
s1 = new BitArray(tab.terminals.Count);
while (p != null) {
s2 = tab.Expected0(p.sub, curSy);
// must not optimize with switch statement, if there are ll1 warnings
if (Overlaps(s1, s2)) { return false; }
s1.Or(s2);
++nAlts;
// must not optimize with switch-statement, if alt uses a resolver expression
if (p.sub.typ == Node.rslv) return false;
p = p.down;
}
return nAlts > 5;
}
示例3: BitArrayDemo
static void BitArrayDemo()
{
var bits1 = new BitArray(8);
bits1.SetAll(true);
bits1.Set(1, false);
bits1[5] = false;
bits1[7] = false;
Console.Write("initialized: ");
DisplayBits(bits1);
Console.WriteLine();
DisplayBits(bits1);
bits1.Not();
Console.Write(" not ");
DisplayBits(bits1);
Console.WriteLine();
var bits2 = new BitArray(bits1);
bits2[0] = true;
bits2[1] = false;
bits2[4] = true;
DisplayBits(bits1);
Console.Write(" or ");
DisplayBits(bits2);
Console.Write(" : ");
bits1.Or(bits2);
DisplayBits(bits1);
Console.WriteLine();
DisplayBits(bits2);
Console.Write(" and ");
DisplayBits(bits1);
Console.Write(" : ");
bits2.And(bits1);
DisplayBits(bits2);
Console.WriteLine();
DisplayBits(bits1);
Console.Write(" xor ");
DisplayBits(bits2);
bits1.Xor(bits2);
Console.Write(" : ");
DisplayBits(bits1);
Console.WriteLine();
}
示例4: Or
public void Or()
{
BitArray array1 = new BitArray(4);
BitArray array2 = new BitArray(4);
array1[0] = true;
array1[1] = false;
array1[2] = false;
array1[3] = false;
array2[0] = true;
array2[1] = false;
array2[2] = true;
array2[3] = true;
array1.Or(array2);
Assert.AreEqual(true, array1[0]);
Assert.AreEqual(false, array1[1]);
Assert.AreEqual(true, array1[2]);
Assert.AreEqual(true, array1[3]);
}
示例5: ConfirmSignupGump
public ConfirmSignupGump( Mobile from, Mobile registrar, Tournament tourny, ArrayList players )
: base(50, 50)
{
m_From = from;
m_Registrar = registrar;
m_Tournament = tourny;
m_Players = players;
m_From.CloseGump( typeof( AcceptTeamGump ) );
m_From.CloseGump( typeof( AcceptDuelGump ) );
m_From.CloseGump( typeof( DuelContextGump ) );
m_From.CloseGump( typeof( ConfirmSignupGump ) );
#region Rules
Ruleset ruleset = tourny.Ruleset;
Ruleset basedef = ruleset.Base;
int height = 185 + 60 + 12;
int changes = 0;
BitArray defs;
if ( ruleset.Flavors.Count > 0 )
{
defs = new BitArray( basedef.Options );
for ( int i = 0; i < ruleset.Flavors.Count; ++i )
defs.Or( ((Ruleset)ruleset.Flavors[i]).Options );
height += ruleset.Flavors.Count * 18;
}
else
{
defs = basedef.Options;
}
BitArray opts = ruleset.Options;
for ( int i = 0; i < opts.Length; ++i )
{
if ( defs[i] != opts[i] )
++changes;
}
height += (changes * 22);
height += 10 + 22 + 25 + 25;
if ( tourny.PlayersPerParticipant > 1 )
height += 36 + (tourny.PlayersPerParticipant * 20);
#endregion
Closable = false;
AddPage( 0 );
//AddBackground( 0, 0, 400, 220, 9150 );
AddBackground( 1, 1, 398, height, 3600 );
//AddBackground( 16, 15, 369, 189, 9100 );
AddImageTiled( 16, 15, 369, height - 29, 3604 );
AddAlphaRegion( 16, 15, 369, height - 29 );
AddImage( 215, -43, 0xEE40 );
//AddImage( 330, 141, 0x8BA );
StringBuilder sb = new StringBuilder();
if ( tourny.TournyType == TournyType.FreeForAll )
{
sb.Append( "FFA" );
}
else if ( tourny.TournyType == TournyType.RandomTeam )
{
sb.Append( "Team" );
}
else if ( tourny.TournyType == TournyType.RedVsBlue )
{
sb.Append( "Red v Blue" );
}
else
{
for ( int i = 0; i < tourny.ParticipantsPerMatch; ++i )
{
if ( sb.Length > 0 )
sb.Append( 'v' );
sb.Append( tourny.PlayersPerParticipant );
}
}
if ( tourny.EventController != null )
sb.Append( ' ' ).Append( tourny.EventController.Title );
sb.Append( " Tournament Signup" );
AddBorderedText( 22, 22, 294, 20, Center( sb.ToString() ), LabelColor32, BlackColor32 );
AddBorderedText( 22, 50, 294, 40, "You have requested to join the tournament. Do you accept the rules?", 0xB0C868, BlackColor32 );
//.........这里部分代码省略.........
示例6: ComputeGlobalLiveSets
private void ComputeGlobalLiveSets()
{
bool changed = true;
while (changed)
{
changed = false;
for (int i = basicBlocks.Count - 1; i >= 0; i--)
{
var block = extendedBlocks[i];
BitArray liveOut = new BitArray(registerCount);
foreach (var next in block.BasicBlock.NextBlocks)
{
liveOut.Or(extendedBlocks[next.Sequence].LiveIn);
}
BitArray liveIn = (BitArray)block.LiveOut.Clone();
liveIn.And(block.LiveKillNot);
liveIn.Or(block.LiveGen);
// compare them for any changes
if (!changed)
if (!block.LiveOut.AreSame(liveOut) || !block.LiveIn.AreSame(liveIn))
changed = true;
block.LiveOut = liveOut;
block.LiveIn = liveIn;
}
}
}
示例7: MakeSetForConflictSymbols
BitArray MakeSetForConflictSymbols(List<Symbol> conflictSymbols)
{
BitArray arr = new BitArray(terminals.Count);
foreach (Symbol sym in conflictSymbols) {
if (sym.typ == Node.t)
arr[sym.n] = true;
else if (sym.typ == Node.nt) {
Debug.Assert(sym.firstReady);
arr.Or(sym.first);
}
}
return arr;
}
示例8: ReadyUpGump
//.........这里部分代码省略.........
AddHtml( 35 + offset, y, 166, 20, name, false, false );
y += 22;
}
}
y += 8;
AddHtml( 35, y, 176, 20, "Continue?", false, false );
y -= 2;
AddButton( 102, y, 247, 248, 0, GumpButtonType.Page, 2 );
AddButton( 169, y, 242, 241, 2, GumpButtonType.Reply, 0 );
#endregion
#region Rules
AddPage( 2 );
Ruleset ruleset = context.Ruleset;
Ruleset basedef = ruleset.Base;
height = 25 + 20 + 5 + 20 + 20 + 4;
int changes = 0;
BitArray defs;
if ( ruleset.Flavors.Count > 0 )
{
defs = new BitArray( basedef.Options );
for ( int i = 0; i < ruleset.Flavors.Count; ++i )
defs.Or( ((Ruleset)ruleset.Flavors[i]).Options );
height += ruleset.Flavors.Count * 18;
}
else
{
defs = basedef.Options;
}
BitArray opts = ruleset.Options;
for ( int i = 0; i < opts.Length; ++i )
{
if ( defs[i] != opts[i] )
++changes;
}
height += (changes * 22);
height += 10 + 22 + 25;
AddBackground( 0, 0, 260, height, 9250 );
AddBackground( 10, 10, 240, height - 20, 0xDAC );
AddHtml( 35, 25, 190, 20, Center( "Rules" ), false, false );
AddHtml( 35, 50, 190, 20, String.Format( "Set: {0}", basedef.Title ), false, false );
y = 70;
for ( int i = 0; i < ruleset.Flavors.Count; ++i, y += 18 )
AddHtml( 35, y, 190, 20, String.Format( " + {0}", ((Ruleset)ruleset.Flavors[i]).Title ), false, false );
示例9: MessageRuleset
private void MessageRuleset( Mobile mob ) {
if ( m_Ruleset == null ) {
return;
}
Ruleset ruleset = m_Ruleset;
Ruleset basedef = ruleset.Base;
mob.SendMessage( "Ruleset: {0}", basedef.Title );
BitArray defs;
if ( ruleset.Flavors.Count > 0 )
{
defs = new BitArray( basedef.Options );
for ( int i = 0; i < ruleset.Flavors.Count; ++i ) {
defs.Or( ((Ruleset)ruleset.Flavors[i]).Options );
mob.SendMessage( " + {0}", ((Ruleset)ruleset.Flavors[i]).Title );
}
}
else
{
defs = basedef.Options;
}
int changes = 0;
BitArray opts = ruleset.Options;
for ( int i = 0; i < opts.Length; ++i )
{
if ( defs[i] != opts[i] ) {
string name = ruleset.Layout.FindByIndex( i );
if ( name != null ) // sanity
{
++changes;
if ( changes == 1 ) {
mob.SendMessage( "Modifications:" );
}
mob.SendMessage( "{0}: {1}", name, opts[i] ? "enabled" : "disabled" );
}
}
}
}
示例10: CheckAlts
void CheckAlts(Node p) {
BitArray s1, s2;
while (p != null) {
if (p.typ == Node.alt) {
Node q = p;
s1 = new BitArray(terminals.Count);
while (q != null) { // for all alternatives
s2 = Expected0(q.sub, curSy);
CheckOverlap(s1, s2, 1);
s1.Or(s2);
CheckAlts(q.sub);
q = q.down;
}
} else if (p.typ == Node.opt || p.typ == Node.iter) {
if (DelSubGraph(p.sub)) LL1Error(4, null); // e.g. [[...]]
else {
s1 = Expected0(p.sub, curSy);
s2 = Expected(p.next, curSy);
CheckOverlap(s1, s2, 2);
}
CheckAlts(p.sub);
} else if (p.typ == Node.any) {
if (Sets.Elements(p.set) == 0) LL1Error(3, null);
// e.g. {ANY} ANY or [ANY] ANY or ( ANY | ANY )
}
if (p.up) break;
p = p.next;
}
}
示例11: First0
//---------------------------------------------------------------------
// Symbol set computations
//---------------------------------------------------------------------
/* Computes the first set for the graph rooted at p */
BitArray First0(Node p, BitArray mark) {
BitArray fs = new BitArray(terminals.Count);
while (p != null && !mark[p.n]) {
mark[p.n] = true;
switch (p.typ) {
case Node.nt: {
if (p.sym.firstReady) fs.Or(p.sym.first);
else fs.Or(First0(p.sym.graph, mark));
break;
}
case Node.t: case Node.wt: {
fs[p.sym.n] = true; break;
}
case Node.any: {
fs.Or(p.set); break;
}
case Node.alt: {
fs.Or(First0(p.sub, mark));
fs.Or(First0(p.down, mark));
break;
}
case Node.iter: case Node.opt: {
fs.Or(First0(p.sub, mark));
break;
}
}
if (!DelNode(p)) break;
p = p.next;
}
return fs;
}
示例12: GenCond
void GenCond(BitArray s, Node p, bool allowExtractResolvers)
{
if (p.typ == Node.rslv) CopySourcePart(p.pos, 0);
else if (p.typ == Node.alt && allowExtractResolvers) {
List<Position> resolvers = new List<Position>();
s = new BitArray(s.Length);
for (Node node = p; node != null; node = node.down) {
if (node.sub.typ == Node.rslv && node.sub.resolverWasExtracted) {
resolvers.Add(node.sub.pos);
} else {
s.Or(tab.First(node.sub));
}
}
GenCond(s, p, false);
foreach (Position resolver in resolvers) {
gen.Write(" || (");
CopySourcePart(resolver, 0);
gen.Write(")");
}
} else {
int n = Sets.Elements(s);
if (n == 0) gen.Write("false"); // happens if an ANY set matches no symbol
else if (n <= maxTerm)
foreach (Symbol sym in tab.terminals) {
if (s[sym.n]) {
gen.Write("la.kind == {0}", sym.n);
--n;
if (n > 0) gen.Write(" || ");
}
}
else
gen.Write("StartOf({0})", NewCondSet(s));
}
}
示例13: Walk
// SwitchStatement
protected internal override bool Walk(SwitchStatement node)
{
// The expression is evaluated always.
// Then each case clause expression is evaluated until match is found.
// Therefore, the effects of the case clause expressions accumulate.
// Default clause is evaluated last (so all case clause expressions must
// accumulate first)
WalkNode(node.TestValue);
// Flow all the cases, they all start with the same initial state
int count;
IList<SwitchCase> cases = node.Cases;
if (cases != null && (count = cases.Count) > 0) {
SwitchCase @default = null;
// Save the initial state
BitArray entry = _bits;
// The state to progressively accumualte effects of the case clause expressions
BitArray values = new BitArray(entry);
// State to flow the case clause bodies.
BitArray caseFlow = new BitArray(_bits.Length);
// The state to accumulate results into
BitArray result = new BitArray(_bits.Length, true);
PushStatement(result);
for (int i = 0; i < count; i++) {
if (cases[i].IsDefault) {
Debug.Assert(@default == null);
// postpone the default case
@default = cases[i];
continue;
}
// Set the state for the walking of the body
caseFlow.SetAll(false);
caseFlow.Or(values);
// Walk the body
_bits = caseFlow;
WalkNode(cases[i].Body);
// Accumulate the result into the overall case statement result.
result.And(caseFlow);
}
// Walk the default at the end.
if (@default != null) {
// Initialize
caseFlow.SetAll(false);
caseFlow.Or(values);
// Walk the default body
_bits = caseFlow;
WalkNode(@default.Body);
// Accumulate.
result.And(caseFlow);
// If there's a default clause, exactly one case got executed.
// The final state is 'and' across all cases, stored in 'result'
entry.SetAll(false);
entry.Or(result);
} else {
// In the absence of default clause, we may have executed case,
// but didn't have to, so the result is an 'and' between the cases
// and the initial state.
entry.And(result);
}
PopStatement();
// Restore the original state.
_bits = entry;
}
return false;
}
示例14: FindAS
void FindAS(Node p)
{
// find ANY sets
Node a;
while (p != null) {
if (p.typ == Node.opt || p.typ == Node.iter) {
FindAS(p.sub);
a = LeadingAny(p.sub);
if (a != null) Sets.Subtract(a.set, First(p.next));
} else if (p.typ == Node.alt) {
BitArray s1 = new BitArray(terminals.Count);
Node q = p;
while (q != null) {
FindAS(q.sub);
a = LeadingAny(q.sub);
if (a != null)
Sets.Subtract(a.set, First(q.down).Or(s1));
else
s1.Or(First(q.sub));
q = q.down;
}
}
if (p.up) break;
p = p.next;
}
}
示例15: UpdateEntrySet
private bool UpdateEntrySet(BitArray entrySet, BitArray exitSet, BitArray useBeforeDef, BitArray notDef)
{
int card = entrySet.Cardinality();
entrySet.Or(exitSet);
entrySet.And(notDef);
entrySet.Or(useBeforeDef);
return entrySet.Cardinality() != card;
}