Skip to main content

C++ unordered map for Python

Tested against Windows 10 / Python 3.11 / Anaconda / C++ 20 - MSVC

pip install cppumap

Cython and a C++ compiler must be installed!

from cppumap.um_int__int import Um_int_int
import numpy as np

di = {k: k + 1 for k in range(100)}
di2 = {k: k - 100 for k in range(100, 200)}
stufftodeletelater = list(di2.items())
di.update(di2)
m = Um_int_int(di)
print(m)
stufftodelete = list(range(20))
del m[stufftodelete]
print(m)
values2delete = list(range(90, 100))
m.del_by_values(values2delete)
print(m)
m.del_by_values(79)
print(m)
m.del_by_key_and_value(stufftodeletelater)
print(m)
a = np.arange(100, dtype=np.int32)
b = np.arange(100, dtype=np.int32)
m.set_np(a, b)
print(m)
tuplelist = [(k, k + 1) for k in range(300, 400)]
m.set_tuple_list(tuplelist)
print(m)
print(m.getitems(a))
print(m.sorted())
for k, v in m.items():
    print(k, v)
for k in m:
    print(k)
print(m.keys())
print(m.values())
di3 = {k: k - 100 for k in range(1000, 1200)}
m.update(di3)
print(m)
cop = m.copy()
print(cop)
m.append(100000 - 1, 1)
print(m)

my_results_apply_as_c_function = []
my_results_apply_as_c_pyfunction = []
my_results_apply_as_c_function_nogil = []



def apply_as_c_function(a):
    my_results_apply_as_c_function.append(a)


def apply_as_c_pyfunction(a):
    my_results_apply_as_c_pyfunction.append(a)


def apply_function(a, b):
    return b, a


def apply_as_c_function_nogil(a):
    my_results_apply_as_c_function_nogil.append(a)  # might not release the gil


results1 = m.apply_function(apply_function)
print(results1)
m.apply_as_c_function(apply_as_c_function)
n2 = (
    np.array([q for q in my_results_apply_as_c_function if q is not None], dtype=np.uint64)
    .view(np.int32)
    .reshape((-1, 2))
)
m.apply_as_c_pyfunction(apply_as_c_pyfunction)

n1 = (
    np.array(
        [q for q in my_results_apply_as_c_pyfunction if q is not None], dtype=np.uint64
    )
    .view(np.int32)
    .reshape((-1, 2))
)

m.apply_as_c_function_nogil(apply_as_c_function_nogil)
n3 = (
    np.array(
        [q for q in my_results_apply_as_c_function_nogil if q is not None],
        dtype=np.uint64,
    )
    .view(np.int32)
    .reshape((-1, 2))
)
m.pop(9999)

Metadata

Release files for cppumap 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cppumap 0.10
File Size Uploaded
cppumap-0.10.tar.gz 26.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cppumap 0.10
File Interpreter ABI Platform
cppumap-0.10-py3-none-any.whl Python 3 none any Details

Total release size: 54.7 kB

Release files / cppumap-0.10.tar.gz

Download URL cppumap-0.10.tar.gz
Size 26.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d36a9b4952359636c6558269f2ed6305e660057f78cf77a38829a3bec3761183
BLAKE2b-256 checksum
How to use checksums
514cb33bee6a93ac0ffbe34d9ce4f278bf1c3e4cd5e2088d0628ffccf4ce9fa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / cppumap-0.10-py3-none-any.whl

Download URL cppumap-0.10-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82156370625509443b09477cdcf4b06069aa5556b285d77828603a21737accc0
BLAKE2b-256 checksum
How to use checksums
4012d0790aee94d5d16b95b11b284f946f6d8ccdaef4bd9415954ba5c531cba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page