OpenQuizz
Une application de gestion des contenus pédagogiques
PSet Class Reference
Inheritance diagram for PSet:
Collaboration diagram for PSet:

Data Structures

class  _Evolver
 

Public Member Functions

def __new__ (cls, m)
 
def __contains__ (self, element)
 
def __iter__ (self)
 
def __len__ (self)
 
def __repr__ (self)
 
def __str__ (self)
 
def __hash__ (self)
 
def __reduce__ (self)
 
def add (self, element)
 
def update (self, iterable)
 
def remove (self, element)
 
def discard (self, element)
 
def copy (self)
 
def evolver (self)
 

Static Public Attributes

 issubset
 
 issuperset
 
 union
 
 intersection
 
 difference
 
 symmetric_difference
 
 isdisjoint
 

Detailed Description

Persistent set implementation. Built on top of the persistent map. The set supports all operations
in the Set protocol and is Hashable.

Do not instantiate directly, instead use the factory functions :py:func:`s` or :py:func:`pset`
to create an instance.

Random access and insert is log32(n) where n is the size of the set.

Some examples:

>>> s = pset([1, 2, 3, 1])
>>> s2 = s.add(4)
>>> s3 = s2.remove(2)
>>> s
pset([1, 2, 3])
>>> s2
pset([1, 2, 3, 4])
>>> s3
pset([1, 3, 4])

Member Function Documentation

◆ __contains__()

def __contains__ (   self,
  element 
)

◆ __hash__()

def __hash__ (   self)

◆ __iter__()

def __iter__ (   self)

◆ __len__()

def __len__ (   self)

◆ __new__()

def __new__ (   cls,
  m 
)

Reimplemented in CheckedPSet.

◆ __reduce__()

def __reduce__ (   self)

Reimplemented in CheckedPSet.

◆ __repr__()

def __repr__ (   self)

Reimplemented in CheckedPSet.

◆ __str__()

def __str__ (   self)

Reimplemented in CheckedPSet.

◆ add()

def add (   self,
  element 
)
Return a new PSet with element added

>>> s1 = s(1, 2)
>>> s1.add(3)
pset([1, 2, 3])

◆ copy()

def copy (   self)

◆ discard()

def discard (   self,
  element 
)
Return a new PSet with element removed. Returns itself if element is not present.

◆ evolver()

def evolver (   self)
Create a new evolver for this pset. For a discussion on evolvers in general see the
documentation for the pvector evolver.

Create the evolver and perform various mutating updates to it:

>>> s1 = s(1, 2, 3)
>>> e = s1.evolver()
>>> _ = e.add(4)
>>> len(e)
4
>>> _ = e.remove(1)

The underlying pset remains the same:

>>> s1
pset([1, 2, 3])

The changes are kept in the evolver. An updated pmap can be created using the
persistent() function on the evolver.

>>> s2 = e.persistent()
>>> s2
pset([2, 3, 4])

The new pset will share data with the original pset in the same way that would have
been done if only using operations on the pset.

Reimplemented in CheckedPSet.

◆ remove()

def remove (   self,
  element 
)
Return a new PSet with element removed. Raises KeyError if element is not present.

>>> s1 = s(1, 2)
>>> s1.remove(2)
pset([1])

◆ update()

def update (   self,
  iterable 
)
Return a new PSet with elements in iterable added

>>> s1 = s(1, 2)
>>> s1.update([3, 4, 4])
pset([1, 2, 3, 4])

Field Documentation

◆ difference

difference
static

◆ intersection

intersection
static

◆ isdisjoint

isdisjoint
static

◆ issubset

issubset
static

◆ issuperset

issuperset
static

◆ symmetric_difference

symmetric_difference
static

◆ union

union
static

The documentation for this class was generated from the following file: