List API: ¶
Module shared_atomic
-
List provide atomic operations, the list should be no longer than 8 bytes
:attributes encoding: readonly string character set
initial_length: readonly total length in bits
value: read/write value of the list
int_value: readonly int value
size: readonly size of the list
mode: readonly ‘s’ for single process, ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported
constructor to initialize the set, the set should be no longer than 8 bytes
- Parameters
-
-
initial – initial value of the set, if the initial value is longer than 8 bytes, please specify the trimming target length, or else it would fail.n
-
mode – the mode in which the set will be shared. ‘singleprocessing’ or ‘s’ for single process, ‘multiprocessing’ or ‘m’ for multiprocessing, on windows platform, only singleprocessing is supported, setting it to ‘m’ or ‘multiprocessing’ will be ignored.n
-
encoding – , character set, default ‘utf-8’n
-
windows_unix_compatibility – whether the source code should be compatible with windows x64
-
-
Switch between singleprocessing mode and multiprocessing mode, the contents will be copied , other threads/processes would not be aware of the change.
- Parameters
-
-
newmode – the mode to change to, ‘m’ for multiproessing, ‘s’ for singleprocessing. default ‘m’
-
windows_unix_compatibility – if change to multiprocessing mode, whether the source code should be compatible with windows x64
-
- Returns
-
None
-
Function to decode the bytes to set
- Parameters
-
-
bits_in_bytes – bytes needs to be decoded
-
encoding – character encoding
-
- Returns
-
the decoded list
-
function to encode the input_set with specific character encoding
- Parameters
-
-
input_list – input set
-
encoding – character encoding
-
- Returns
-
(data in integer representation, total length in bits)
-
Get the whole integer representation from the set, the whole list would be treated as a large integer
- Returns
-
the integer representation
-
Get the list atomically
- Returns
-
the list
-
same with get_int
-
Compare and list atomically, This compares the contents of self with the contents of i. If equal, the operation is a read-modify-write operation that writes n into self. If they are not equal, the operation is a read and the current contents of itself are written into i.
- Parameters
-
-
i – the list to be compared with
-
n – another bytes to be ready to set to self if comparision return True
-
- Returns
-
if self is equal to i return True, else return False
-
Compare and swap atomically, This compares the contents of self with the contents of n. If equal, the operation is a read-modify-write operation that writes n into self. If they are not equal, No operation is performed.
- Parameters
-
-
i – exchange value
-
n – The value to be compared with
-
- Returns
-
the initial value of self
-
Get and set atomically
- Parameters
-
data – new data to set
- Returns
-
the original list
-
Value exchange between 3 atomic_lists in 2 groups atomically, store i in itself after store itself in j
- Parameters
-
-
i – one atomic_list
-
j – another atomic_list
-
- Returns
-
None
-
Atomically store contents from another list to this list, if the other list is different with this one in size , the function will fail.
- Parameters
-
i – another list to store its value to self
- Returns
-
None
-
Change the encoding of the atomic_list, if the original size is not enough, it will elongate the list, which is only valid in the master process/thread, if 8 bytes are not enough, it will fail.
- Parameters
-
newencode – new encoding, such as ‘utf-8’, ‘utf-16-le’
- Returns
-
None
-
Set the whole integer representation from the set, the whole list would be treated as a large integer
- Returns
-
None
-
Set the value in the list, if the new data is longer than the original size of the list. it will expand the set accordingly which could only be used in the master process/thread the size of the set can be checked with self.size
- Parameters
-
data – input list
- Returns
-
None
-
Function to finish the shift and add of the data prefix
- Parameters
-
-
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
-
- Returns
-
(data_prefix, accumulate_length)
-
same with get_list and set_list