Core: Floor and ceil in datastorage (#2448)
This commit is contained in:
parent
d892622ab1
commit
530e792c3c
|
@ -10,6 +10,7 @@ import hashlib
|
||||||
import inspect
|
import inspect
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import operator
|
import operator
|
||||||
import pickle
|
import pickle
|
||||||
import random
|
import random
|
||||||
|
@ -67,21 +68,25 @@ def update_dict(dictionary, entries):
|
||||||
|
|
||||||
# functions callable on storable data on the server by clients
|
# functions callable on storable data on the server by clients
|
||||||
modify_functions = {
|
modify_functions = {
|
||||||
"add": operator.add, # add together two objects, using python's "+" operator (works on strings and lists as append)
|
# generic:
|
||||||
"mul": operator.mul,
|
|
||||||
"mod": operator.mod,
|
|
||||||
"max": max,
|
|
||||||
"min": min,
|
|
||||||
"replace": lambda old, new: new,
|
"replace": lambda old, new: new,
|
||||||
"default": lambda old, new: old,
|
"default": lambda old, new: old,
|
||||||
|
# numeric:
|
||||||
|
"add": operator.add, # add together two objects, using python's "+" operator (works on strings and lists as append)
|
||||||
|
"mul": operator.mul,
|
||||||
"pow": operator.pow,
|
"pow": operator.pow,
|
||||||
|
"mod": operator.mod,
|
||||||
|
"floor": lambda value, _: math.floor(value),
|
||||||
|
"ceil": lambda value, _: math.ceil(value),
|
||||||
|
"max": max,
|
||||||
|
"min": min,
|
||||||
# bitwise:
|
# bitwise:
|
||||||
"xor": operator.xor,
|
"xor": operator.xor,
|
||||||
"or": operator.or_,
|
"or": operator.or_,
|
||||||
"and": operator.and_,
|
"and": operator.and_,
|
||||||
"left_shift": operator.lshift,
|
"left_shift": operator.lshift,
|
||||||
"right_shift": operator.rshift,
|
"right_shift": operator.rshift,
|
||||||
# lists/dicts
|
# lists/dicts:
|
||||||
"remove": remove_from_list,
|
"remove": remove_from_list,
|
||||||
"pop": pop_from_container,
|
"pop": pop_from_container,
|
||||||
"update": update_dict,
|
"update": update_dict,
|
||||||
|
|
|
@ -415,6 +415,8 @@ The following operations can be applied to a datastorage key
|
||||||
| mul | Multiplies the current value of the key by `value`. |
|
| mul | Multiplies the current value of the key by `value`. |
|
||||||
| pow | Multiplies the current value of the key to the power of `value`. |
|
| pow | Multiplies the current value of the key to the power of `value`. |
|
||||||
| mod | Sets the current value of the key to the remainder after division by `value`. |
|
| mod | Sets the current value of the key to the remainder after division by `value`. |
|
||||||
|
| floor | Floors the current value (`value` is ignored). |
|
||||||
|
| ceil | Ceils the current value (`value` is ignored). |
|
||||||
| max | Sets the current value of the key to `value` if `value` is bigger. |
|
| max | Sets the current value of the key to `value` if `value` is bigger. |
|
||||||
| min | Sets the current value of the key to `value` if `value` is lower. |
|
| min | Sets the current value of the key to `value` if `value` is lower. |
|
||||||
| and | Applies a bitwise AND to the current value of the key with `value`. |
|
| and | Applies a bitwise AND to the current value of the key with `value`. |
|
||||||
|
|
Loading…
Reference in New Issue