3 ms·
(TL;DR - this is a concept that computer science borrowed from math) In math (say abstract algebra / group theory), the operations on your database form a grou
by dunham 10y ago
(TL;DR - this is a concept that computer science borrowed from math)
In math (say abstract algebra / group theory), the operations on your database form a group under composition. Given two operations f,g (say f is "subtract $10" and g is "subtract $20"), the composition of those operations could be written "f•g" (depending on notation this can mean g is done first or f is done first, typically the former convention is used).
(So, instead of numbers and plus (+) in your example, we're using functions and composition (•) as our group.)
This group, of operations under composition, is said to be commutative if f•g = g•f for all f and g. (That is for all combinations of your possible operations.)
For addition/subtraction operations you're good to go.
If you can consider operations on a hash table being things like 'set a value of 10 for key "a"' the order that the operations are executed in do matter, and the group of those operations, under composition, is not commutative.
The subject of CRDT's in computer science is an attempt to create data types whose operations are commutative.
One reason to want do deal with commutative operations is that you don't have to figure out the order in which the operations officially occurred.