A collection of useful extensions for python implement in C.
Project description
- Python:
>= 3.4
- Version:
- 0.0.4
Installation
Install and update using pip (python3 only):
pip install -U ctools
API
A consistent hash implement. See paper at jump_consistent_hash.
jump_consistent_hash(key: int, num_buckets: int) -> int:
"""Generate a number in the range [0, num_buckets).
This function uses C bindings for speed.
:param key: The key to hash.
:type key: int
:param num_buckets: Number of buckets to use.
:type num_buckets: int
:return: hash number
:rtype: int
"""
A normal hash function for str with consistent value.
strhash(s: str) -> int:
"""
hash str with consistent value.
This function uses C bindings for speed.
:param s: The string to hash.
:type s: string
:return: hash number
:rtype: int
"""
Transfer integer like 20170101 (Java style) to python datetime object.
int8_to_datetime(date_integer: int) -> datetime.datetime:
"""
Convert int like 20180101 to datetime.datetime(2018, 1, 1)).
This function uses C bindings for speed.
:param date_integer: The string to hash.
:type date_integer: int
:return: parsed datetime
:rtype: datetime.datetime
"""
Benchmark
$ make install && make benchmark
int8_to_datetime, 63.481 ns ± 4.179 nseach (10 runs, 1,000,000 loops)
jump_consistent_hash, 156.082 ns ± 6.489 nseach (10 runs, 1,000,000 loops)
strhash, 139.542 ns ± 4.268 nseach (10 runs, 1,000,000 loops)
How To Test
$ make install && make test
More
$ make help
What’s important is free.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ctools-0.0.4.tar.gz
(8.8 kB
view hashes)
Built Distributions
Close
Hashes for ctools-0.0.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca0f66a2144492813725a33348e203940f02a81c603bf98ff270ce407b50a544 |
|
MD5 | b2e15ec755e69f7df27568b7af77ae5c |
|
BLAKE2b-256 | fd148399c4ef307e3590819ce4da6208fee6d3274e555a120b3252a9c2e1b085 |
Close
Hashes for ctools-0.0.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cebb34e513a20873810dbaf8b88348deb523aeb948d07e1664d483f8ad2bd16 |
|
MD5 | 6d2304eb727633a1c6790673cd24a653 |
|
BLAKE2b-256 | b36435963260e06c7e9cd0204e53c70784c0d7bdea947eab19eb771ddbc4e2a0 |