mongo裡的狀態位運算 bit

2021-08-27 05:30:14 字數 897 閱讀 1786

今天用到了位運算,若干個子狀態符合一定要求時,判定其父狀態。

handler.db.task.find_and_modify(query=

, update=},

'$set':,

},new=

true

)

首先,在mongo中,find_and_modify是原子操作:

findandmodify 強調操作的原子性(atomically),比如用來實現自增1的操作或者操作佇列。屬於 get-and-set 式的操作,一般來講,findandmodify 比update操作稍慢,因為需要等待資料庫的響應。

當子狀態為boolean值時,可以採用位運算,update中 '$bit』可以支援 與、或、亦或等操作。

$bit

definition

$bit

the $bit operator performs a bitwise update of a field. the operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations. to specify a $bit operator expression, use the following prototype:

}}note

all numbers in the mongo shell are doubles, not integers. use the numberint() or the numberlong() constructor to specify integers. see numberint or numberlong for more information.

mysql裡的位運算小結

按位與 符合可以有多個運算元同時進行按位與運算,在具體運算時按照從左到右的順序依次計算 1與1為1,其他的為0 按位或 可以有多個符號同時進行或運算,在具體運算時按照從左到右的順序依次計算 1與任何數的或運算的結果都為1,0與0的或運算為0 按位取反,位運算中的唯一單運算元位運算子 即1取反的運算結...

基於陣列的位運算3 按bit位反轉陣列

對於給定的陣列uchar a,以及bit位長度 不是陣列本身長度 如何實現陣列按位長度的反轉演算法,效率一定要高哦 大多數人首先想到的是首尾測試每個bit是否為0,1 本部落格有關於如何測試,設定bit 然後在交換bit位 這種演算法的複雜度為位長度,有沒有辦法進一步減小複雜度,哪怕是常數因子也行,...

基於陣列的位運算4 位陣列按bit位整體移動

對於memmove,memcpy等c語言記憶體操作函式你一定很熟悉吧,如果不知道,just go search 廢話少說直接進入話題.給你乙個函式 static void shiftbittolow uchar bitarray,const uint bitleng,uint leftbitshif...