Skip to main content

Homogeneous values favoring maximum or minimum for ZODB conflict resolution

Project description

The zope.minmax.AbstractValue class provides a super class which can be subclassed to store arbitrary homogeneous values in a persistent storage and apply different conflict resolution policies.

The subclasses defined here are resolving the conflicts using always either the maximum or the minimum of the conflicting values.

Maximum

The zope.minmax.Maximum class always resolves conflicts favoring the maximum value. Let’s instantiate one object and verify that it satisfies the interface.

>>> import zope.minmax
>>> import zope.interface.verify
>>> max_favored = zope.minmax.Maximum()
>>> zope.interface.verify.verifyObject(
...     zope.minmax.interfaces.IAbstractValue, max_favored)
True

We can confirm that the initial value is zero.

>>> bool(max_favored)
False
>>> print max_favored.value
None

Now, we can store a new value in the object.

>>> max_favored.value = 11
>>> print max_favored.value
11
>>> bool(max_favored)
True

Or we can use the methods.

>>> max_favored.__setstate__(4532)
>>> max_favored.__getstate__()
4532
>>> print max_favored.value
4532
>>> bool(max_favored)
True

Do notice that using a direct assignment to the value attribute is a more natural use.

Minimum

The zope.minmax.Minimum class always resolves conflicts favoring the minimum value. Again, we instantiate an object and verify that it satisfies the interface.

>>> min_favored = zope.minmax.Minimum()
>>> zope.interface.verify.verifyObject(
...     zope.minmax.interfaces.IAbstractValue, min_favored)
True

We need a confirmation that the initial value is zero.

>>> bool(min_favored)
False
>>> print min_favored.value
None

Let’s populate this one too.

>>> min_favored.value = 22
>>> print min_favored.value
22
>>> bool(min_favored)
True

Or we can use the methods, again.

>>> min_favored.__setstate__(8796)
>>> min_favored.__getstate__()
8796
>>> print min_favored.value
8796
>>> bool(min_favored)
True

Please, notice, again, that using a direct assignment to the value attribute is a more natural use.

Conflict Resolution

Now, we need to exercise the conflict resolution interface. First for the zope.minmax.Maximum:

Let’s try differing values larger than the old value.

>>> max_favored._p_resolveConflict(max_favored.value, 4536, 4535)
4536
>>> max_favored._p_resolveConflict(max_favored.value, 4573, 4574)
4574

What happens when all the values are equal, including the old.

>>> max_favored._p_resolveConflict(max_favored.value, 4532, 4532)
4532

Notice that when the old value is larger than both the committed and new, it is still disregarded.

>>> max_favored._p_resolveConflict(max_favored.value, 4531, 4530)
4531

Now, the zope.minmax.Minimum:

Let’s try differing values smaller than the old value.

>>> min_favored._p_resolveConflict(min_favored.value, 8792, 8791)
8791
>>> min_favored._p_resolveConflict(min_favored.value, 8785, 8786)
8785

What happens when all the values are equal, including the old.

>>> min_favored._p_resolveConflict(min_favored.value, 8796, 8796)
8796

Notice that when the old value is smaller than both the committed and new, it is still disregarded.

>>> min_favored._p_resolveConflict(min_favored.value, 8798, 8799)
8798

How about an example that is not numerical?

>>> max_word = zope.minmax.Maximum('joy')
>>> print max_word.value
joy
>>> bool(max_word)
True
>>> max_word._p_resolveConflict(max_word.value, 'happiness', 'exuberance')
'happiness'
>>> max_word._p_resolveConflict(max_word.value, 'exuberance', 'happiness')
'happiness'
>>> min_word = zope.minmax.Minimum(max_word.value)
>>> print min_word.value
joy
>>> bool(min_word)
True
>>> min_word._p_resolveConflict(min_word.value, 'happiness', 'exuberance')
'exuberance'
>>> min_word._p_resolveConflict(min_word.value, 'exuberance', 'happiness')
'exuberance'

As indicated, we don’t need to have numbers, just homegeneous items. The homogeneous values are not really inherently required. However, it makes no sense to apply min() or max() on, say, one number and one string. Simply, the ordering relations do not work at all on heterogeneous values.

Changes

1.0

No further changes since 1.0b2

1.0b2

Removed _p_independent method from AbstractValue class.

1.0b1

Initial release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zope.minmax-1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zope.minmax-1.0-py2.4.egg (8.0 kB view details)

Uploaded Egg

File details

Details for the file zope.minmax-1.0.tar.gz.

File metadata

  • Download URL: zope.minmax-1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zope.minmax-1.0.tar.gz
Algorithm Hash digest
SHA256 e2c03156670a7b7e6add8ab3a5493a997d3fc7fdd4384a8c2b7cc8e6ec39c782
MD5 9c9c10d71ce6ff9d799d5dd4b40b4d48
BLAKE2b-256 a0d2fe654b60c33e10759132e5597fa1674c5611f97c51cc3b47fa906ebf4b0a

See more details on using hashes here.

File details

Details for the file zope.minmax-1.0-py2.4.egg.

File metadata

  • Download URL: zope.minmax-1.0-py2.4.egg
  • Upload date:
  • Size: 8.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zope.minmax-1.0-py2.4.egg
Algorithm Hash digest
SHA256 7bcc15080e86eb95d88f39da37b6fa0716bf80d25b3d85dcb9ccf436d0799362
MD5 800ee25837466528c7878e93ac476f72
BLAKE2b-256 0daf00b17ead1e7c5ffbbcc432478278e2f0a08f95bc6dee0426023b850e3ad4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page