private byte SetBitFree(byte byteToAnalize, int shift) { var bits = new MyBitArray(byteToAnalize); bits[shift] = false; return(bits.ToByte()); }
private IEnumerable <int> GetFreeBlocks(int reqBlocksNum) { var blocks = new List <int>(); if (GetNumber_Of_Free_Blocks() < reqBlocksNum) { return(blocks); } int fileSize = GetFileSize(List_BlocksFileIndex); int offset = GetByteStartList_Blocks(); offset += GetBlockStartData(); int startByte = offset; int endByte = offset + fileSize; int readBytes = 0; stream.Position = startByte; while (stream.Position < endByte && blocks.Count < reqBlocksNum) { byte readByte = (byte)stream.ReadByte(); if (readByte != 0b11_11_11_11) { var freeBitsInThisByte = GetFreeBitsNumbers(readByte); foreach (var bitNumber in freeBitsInThisByte) { if (blocks.Count == reqBlocksNum) { return(blocks); } else { blocks.Add(startByte + readByte * 8 + bitNumber); } } } readBytes++; } return(blocks); List <int> GetFreeBitsNumbers(byte byteToAnalyze) { var list = new List <int>(); var bits = new MyBitArray(byteToAnalyze); for (var i = 0; i < bits.Length; i++) { if (bits[i] == false) { list.Add(i); } } return(list); } }
private byte SetBitBusy(byte byteToAnalize, int shift) { var bits = new MyBitArray(byteToAnalize); bits[shift] = true; return(bits.ToByte()); }
public void Or(MyBitArray other) { SetLength(Math.Max(Length, other.Length)); for (var i = 0; i < other._array.Length; i++) { _array[i] |= other._array[i]; } }
public State HasAStateInCurrentStates(MyBitArray currentStates) //return true if a diagrams state is in the current state list. { foreach (State curSt in _States) { if ((curSt.id < currentStates.Count) && (currentStates[curSt.id])) { return(curSt); } } return(null); }
public void AddCompFailSet(int[] compList) { MyBitArray addSet = new MyBitArray(compList); int val; if (compFailSets.TryGetValue(addSet, out val)) { compFailSets[addSet] = val + 1; } else { compFailSets.Add(addSet, 1); } }
/// <summary> /// Evaluate the component depending on what state it is in. /// </summary> public bool Evaluate(MyBitArray curStates) { //if (onSuccess) //go through all the OK states //{ // foreach (int id in _okStates) // { // if (curStates[id]) // { // return true; // } // } //} //else //{ if (_failStates == null) { _failStates = new List <int>(); foreach (int id in _singleStateGroup) { if (!_okStates.Contains(id)) { _failStates.Add(id); } } } foreach (int id in _failStates) { if (curStates[id]) { return(true); } } // } return(false); }
public bool Evaluate(MyBitArray curStates, bool success = false) { bool retVal; int cnt = 0; switch (gateType) { case EnGateType.gtAnd: case EnGateType.gtNot: retVal = true; break; case EnGateType.gtOr: case EnGateType.gtNofM: retVal = false; break; default: retVal = false; break; } foreach (EvalDiagram curComp in _compChildren) { switch (gateType) { case EnGateType.gtAnd: retVal = (retVal && curComp.Evaluate(curStates)); if (!retVal) { return(retVal); } break; case EnGateType.gtOr: retVal = (retVal || curComp.Evaluate(curStates)); if (retVal) { return(retVal); } break; case EnGateType.gtNot: return(!curComp.Evaluate(curStates)); case EnGateType.gtNofM: { ++cnt; if (cnt >= val1) { return(true); } } break; } } foreach (LogicNode curNode in _subGates) { switch (gateType) { case EnGateType.gtAnd: retVal = (retVal && curNode.Evaluate(curStates)); if (!retVal) { return(retVal); } break; case EnGateType.gtOr: retVal = (retVal || curNode.Evaluate(curStates)); if (retVal) { return(retVal); } break; case EnGateType.gtNot: return(!curNode.Evaluate(curStates)); case EnGateType.gtNofM: if (curNode.Evaluate(curStates)) { ++cnt; if (cnt >= val1) { return(true); } } break; } } return(retVal); }