Difference between revisions of "User:PROXiCiDE/MathUtil"
Jump to navigation
Jump to search
m
→Bit Array: Rearranged order of helper FN(), Added Comments with small Example usage
imported>PROXiCiDE (fixed contents) |
imported>PROXiCiDE m (→Bit Array: Rearranged order of helper FN(), Added Comments with small Example usage) |
||
Line 184: | Line 184: | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
; int[] bits = BitArray_New(256) | |||
; BitArray_Set(bits,128) | |||
; BitArray_Get(bits,128) | |||
; | |||
; BitArray_Xor(bits,200) | |||
; BitArray_Clear(bits,128) | |||
; BitArray_Xor(bits,200) | |||
Int[] Function BitArray_New(Int aiSize) | |||
Int iSize = Math.Ceiling(ClampInt(aiSize,30,512) / 30) | |||
Int[] iResults = Bit_CreateArray(iSize) | |||
iResults[0] = aiSize | |||
Int i = 1 | |||
While (i < iResults.Length) | |||
iResults[i] = 0 | |||
i += 1 | |||
EndWhile | |||
Return iResults | |||
EndFunction | |||
Function BitArray_Set(Int[] aiBitCTX, Int aiIndex) | |||
Int iIndex = Math.Ceiling(aiIndex / 30) | |||
aiBitCTX[iIndex] = Bit_Set(aiBitCTX[iIndex], aiIndex) | |||
EndFunction | |||
Bool Function BitArray_Get(Int[] aiBitCTX, Int aiIndex) | |||
Int iIndex = Math.Ceiling(aiIndex / 30) | |||
Return Bit_Get(aiBitCTX[iIndex], aiIndex) | |||
EndFunction | |||
Function BitArray_Xor(Int[] aiBitCTX, Int aiIndex) | |||
Int iIndex = Math.Ceiling(aiIndex / 30) | |||
aiBitCTX[iIndex] = Bit_Xor(aiBitCTX[iIndex], aiIndex) | |||
EndFunction | |||
Function BitArray_Clear(Int[] aiBitCTX, Int aiIndex) | |||
Int iIndex = Math.Ceiling(aiIndex / 30) | |||
aiBitCTX[iIndex] = Bit_Clear(aiBitCTX[iIndex], aiIndex) | |||
EndFunction | |||
;Helper function | |||
;Array[0] is Reserved for Bit Size | |||
Int[] Function Bit_CreateArray(Int aiSize) | Int[] Function Bit_CreateArray(Int aiSize) | ||
If aiSize == 1 | If aiSize == 1 | ||
Line 222: | Line 263: | ||
Return New Int[19] | Return New Int[19] | ||
EndIf | EndIf | ||
EndFunction | EndFunction | ||
</source> | </source> |