集合API¶
模塊shared_atomic
原子集合提供原子操作,不應該超過8字節
原子集合的初始化函數,不應該超過8字節
- 參數
initial – 集合的初始值,如果初始值長於8字節,請指定截短後的長度否則會失敗
mode – 原子集合的共享模式,』singleprocessing’或者’s’是單進程模式,』multiprocessing’或者’m’是多進程模式在windows平臺上只支持單進程模式,設成’multiprocessing’或者’m’會被忽略。
encoding – ,字符集,默認使用’utf-8』
在單進程與多進程模式之間切換,原來的內容會被複制到新的共享數組中,因為windows平臺上只有單進程模式,這個函數在windows上並不存在,其它進程或者線程無法感知這種改變
- 參數
newmode – 需要切換的模式,』m』 或者 『multiprocessing』 是多進程模式, 『s』 or 『singleprocessing’單進程模式. 默認值是多進程模式
- 回傳
無
Function to decode the bytes to set
- 參數
bits_in_bytes – bytes needs to be decoded
encoding – character encoding
- 回傳
the decoded set
function to encode the input_set with specific character encoding
- 參數
input_set – input set
encoding – character encoding
- 回傳
(data in integer representation, total length in bits)
獲取集合的整數表示,集合會被當成一個大的整數
- 回傳
整數表示
原子獲取集合
- 回傳
集合
與get_int一致
修改集合當中字符串的字符集,如果原始空間不夠,會增長字符串,如果8字節不夠,它會失敗
- 參數
newencode – 新楄碼,像’utf-8』, 『utf-16-le』
- 回傳
無
原子比較和設置,比較自身和i,如果相等,這個過程就是讀-修改-寫的操作,將n的內容寫入自身,如果不相等,是隻讀操作,自身的內容寫入i.
- 參數
i – 與之比較的集合
n – another set to be ready to set to self if comparision return True
- 回傳
如果自身與i相等返回真,否則返回假。
原子獲取和設置。
- 參數
data – 新數據集
- 回傳
原始數據集
設置集合的整數表示,整個集合當被當成一個大整數
- 回傳
無
設置這個集合的值,如果新數據比原值佔用的空間多,它會擴展集合空間,失去原子性,空間佔用可以用self.size來表示
- 參數
data – input set
- 回傳
無
3個指針之間兩兩交換值,將自己的值存入j然後將i存入自身
- 參數
i – 一個原子集合
j – 另一個原子集合
- 回傳
無
將另一個集合的內容寫入這個集合,如果另一個集合空間佔用與這一個不同,函數會失敗。
- 參數
i – 另一個集合用來設置自身值
- 回傳
無
Function to finish the shift and add of the data prefix
- 參數
data_prefix – integer for the data_prefix
accumulate_length – total data length in bits accumulated so far
input_length – length of the data segment in bits
kind – sorts of data
- 回傳
(data_prefix, accumulate_length)
與get_set和set_set一致