# Set API:¶

Module shared_atomic.atomic_set on Linux and macOS

set provide atomic operations, the set 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 bytearray

int_value: readonly int value

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.**encoding**– , character set, default ‘utf-8’n**mode**– the mode in which the set will be shared. ‘singleprocessing’ or ‘s’ for single process, ‘multiprocessing’ or ‘m’ for multiprocessing.**windows_unix_compatibility**– whether the source code should be compatible with unix platform.

Get the whole integer representation from the set, the whole set would be treated as a large integer

- Returns
the integer representation

Get the set atomically

- Returns
the set

Change the encoding of the string, if the original size is not enough, it will elongate the string, if 8 bytes are not enough, it will fail.

- Parameters
**newencode**– new encoding, such as ‘utf-8’, ‘utf-16-le’- Returns
None

Compare and set atomically. This compares the contents of self with the contents of i. If equal, the operation is a read-modify-write operation that writes data into self. If they are not equal, the operation is a read and the current contents of self are written into i.

- Parameters
**i**– atomic_set object**data**– atomic_set object

- Returns
if j is equal to i return True, else return False

Compare and set 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, no action will be taken.

- Parameters
**n**– the set to be compared with**i**– another bytes to be ready to set to self if comparision return True

- Returns
the original value

Get and set atomically

- Parameters
**data**– new data set- Returns
the original set

Set the whole integer representation from the set, the whole set would be treated as a large integer

- Returns
None

Set the value in the set, if the new data is longer than the original size of the set. it will expand the set accordingly which would lose atomicity. the size of the set can be check with self.size

- Parameters
**data**– input set- Returns
None

Value exchange between 3 pointers in 2 groups atomically, the initial_length field will be updated but not atomically. store i in itself after store itself in j

- Parameters
**i**– one atomic_set**j**– another atomic_set

- Returns
None

Atomically store contents from another set to this set, if the other set is different with this one in size, or the other set is different with this one in encoding, the function will fail.

- Parameters
**i**– the atomic_set to set from- Returns
None

Compare and set atomically. This compares the contents of atomic_set j with the contents of i. If equal, the operation is a read-modify-write operation that writes data into integer. If they are not equal, the operation is a read and the current contents of j are written into i.

- Parameters
**j**– atomic_set object**i**– atomic_set object**data**– atomic_set object

- Returns
if j 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
**intput_set**– target set to change.**i**– the value to set to**n**– The value to be compared with

- Returns
the original set

Get and set atomically

- Parameters
**intput_set**– target set to change.**data**– new data set

- Returns
the original set

Get the whole integer representation from the set, the whole set would be treated as a large integer

- Parameters
**intput_set**– target set.- Returns
the integer representation

Get the set atomically

- Parameters
**intput_set**– target set.- Returns
the set

Set the whole integer representation from the set, the whole set would be treated as a large integer

- Parameters
**intput_set**– target set to change.**integer**– integer representation of the new value.

- Returns
None

Set the value in the set, if the new data is longer than the original size of the set. it will expand the set accordingly which would lose atomicity. the size of the set can be checked with set.size

- Parameters
**intput_set**– target set to change.**data**– input set

- Returns
None

Value exchange between 3 pointers in 2 groups atomically, the initial_length field will be updated but not atomically. store i in n after store n in j

- Parameters
**n**– one atomic_set**i**– one atomic_set**j**– one atomic_set

- Returns
None

Atomically store contents from another set to this set, if the other set is different with this one in size, or the other set is different with this one in encoding, the function will fail.

- Parameters
**n**– the atomic_set to set**i**– the atomic_set to set from

- Returns
None

On Microsoft Windows

set provide atomic operations, the set 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 bytearray

int_value: readonly int value

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.**encoding**– , character set, default ‘utf-8’n**mode**– the mode in which the set will be shared. ‘singleprocessing’ or ‘s’ for single process, ‘multiprocessing’ or ‘m’ for multiprocessing.**windows_unix_compatibility**– whether the source code should be compatible with unix platform.

Get the whole integer representation from the set, the whole set would be treated as a large integer

- Returns
the integer representation

Get the set atomically

- Returns
the set

Change the encoding of the string, if the original size is not enough, it will elongate the string, if 8 bytes are not enough, it will fail.

- Parameters
**newencode**– new encoding, such as ‘utf-8’, ‘utf-16-le’- Returns
None

Compare and set 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 set 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

Get and set atomically

- Parameters
**data**– new data set- Returns
the original set

Set the whole integer representation from the set, the whole set would be treated as a large integer

- Returns
None

Set the value in the set, if the new data is longer than the original size of the set. it will expand the set accordingly which would lose atomicy. the size of the set can be check with self.size

- Parameters
**data**– input set- Returns
None

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
**intput_set**– target set to change.**reference**– the reference used in subprocess**i**– the value to set to**n**– The value to be compared with

- Returns
the original set

Get and set atomically

- Parameters
**intput_set**– target set to change.**reference**– the reference used in subprocess**data**– new data set

- Returns
the original set

Get the whole integer representation from the set, the whole set would be treated as a large integer

- Parameters
**intput_set**– target set.**reference**– the reference used in subprocess

- Returns
the integer representation

Get the set atomically

- Parameters
**intput_set**– target set.**reference**– the reference used in subprocess

- Returns
the set

Set the whole integer representation from the set, the whole set would be treated as a large integer

- Parameters
**intput_set**– target set.**reference**– the reference used in subprocess**integer**– integer representation of the new value.

- Returns
None

Set the value in the set, if the new data is longer than the original size of the set. it will expand the set accordingly which would lose atomicity. the size of the set can be checked with set.size

- Parameters
**intput_set**– target set to change.**reference**– the reference used in subprocess**data**– input set

- Returns
None