Skip to main content

C++ unordered map for Python

Project description

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)

Project details


Release history Release notifications | RSS feed

This version

0.10

Download files

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

Source Distribution

cppumap-0.10.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

cppumap-0.10-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file cppumap-0.10.tar.gz.

File metadata

  • Download URL: cppumap-0.10.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for cppumap-0.10.tar.gz
Algorithm Hash digest
SHA256 d36a9b4952359636c6558269f2ed6305e660057f78cf77a38829a3bec3761183
MD5 a8e985659792b4e82f890c19ee0f3ceb
BLAKE2b-256 514cb33bee6a93ac0ffbe34d9ce4f278bf1c3e4cd5e2088d0628ffccf4ce9fa8

See more details on using hashes here.

File details

Details for the file cppumap-0.10-py3-none-any.whl.

File metadata

  • Download URL: cppumap-0.10-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for cppumap-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 82156370625509443b09477cdcf4b06069aa5556b285d77828603a21737accc0
MD5 29f1a1649dd795495227dd393c1098c3
BLAKE2b-256 4012d0790aee94d5d16b95b11b284f946f6d8ccdaef4bd9415954ba5c531cba7

See more details on using hashes here.

Supported by

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