-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve readme don't support python 3.6 anymore auto format use avx instead of avx2
- Loading branch information
Showing
11 changed files
with
242 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ dist/ | |
|
||
# cython | ||
cython_debug/ | ||
*.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,64 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: 22.10.0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.10.1 | ||
hooks: | ||
- id: isort | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
- id: check-symlinks | ||
- id: check-json | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: debug-statements | ||
- id: detect-private-key | ||
- id: end-of-file-fixer | ||
- id: mixed-line-ending | ||
args: [--fix=no] | ||
- id: requirements-txt-fixer | ||
- id: trailing-whitespace | ||
args: [--markdown-linebreak-ext=md] | ||
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks | ||
rev: v2.14.0 | ||
hooks: | ||
- id: pretty-format-yaml | ||
args: [--autofix] | ||
- repo: https://github.com/tox-dev/pyproject-fmt | ||
rev: 2.1.4 | ||
hooks: | ||
- id: pyproject-fmt | ||
- repo: https://github.com/pre-commit/mirrors-clang-format | ||
rev: v18.1.8 | ||
hooks: | ||
- id: clang-format | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v3.16.0 | ||
hooks: | ||
- id: pyupgrade | ||
args: [--py37-plus] | ||
- repo: https://github.com/MarcoGorelli/cython-lint | ||
rev: v0.16.2 | ||
hooks: | ||
- id: cython-lint | ||
- id: double-quote-cython-strings | ||
- repo: https://github.com/psf/black-pre-commit-mirror | ||
rev: 24.4.2 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/PyCQA/isort | ||
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
- repo: https://github.com/pycqa/flake8 | ||
rev: 7.1.0 | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: | ||
- flake8-annotations | ||
- flake8-bugbear | ||
- flake8-eradicate | ||
- flake8-mutable | ||
- flake8-simplify | ||
- repo: https://github.com/Yelp/detect-secrets | ||
rev: v1.5.0 | ||
hooks: | ||
- id: detect-secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,59 @@ | ||
# cpp-containers-python | ||
|
||
Python wrapper for the C++ Standard Library containers. The behaviour of the containers might not be as expected, since for sorting and hashing the items only the pointer to the Python object is used, and not the actual content. That means items in ordered collections will be ordered according to memory layout and to object content. Furhermore, equality checks will work as pairwise `is` tests, because only the pointers are compared internally. Also certain operations will lead to *undefined behavior*, such as accessing out of bounds indices in `Vector`. | ||
Python wrapper for the C++ Standard Library containers. The behavior of the containers might not be as expected, since for sorting and hashing the items, only the pointer to the Python object is used, and not the actual content. That means items in ordered collections will be ordered according to memory layout and not object content. Furthermore, equality checks will work as pairwise `is` tests, because only the pointers are compared internally. Also certain operations will lead to *undefined behavior*, such as accessing out of bounds indices in `Vector`. | ||
|
||
This design decision was made for performance reasons and to keep the code as simple and close to C++ as possible. Real equality checks can still be implemented by pairwise comparison of the objects at Python level. This won't be any faster than doing so on normal Python collections. | ||
|
||
For more documentation about the C++ containers see <https://en.cppreference.com/w/cpp/container>. | ||
|
||
## Requirements | ||
Python 3.7+. | ||
|
||
## Install | ||
`pip install cpp-containers` (not working yet) | ||
`pip install cpp-containers` | ||
|
||
## Examples | ||
``` | ||
from cppcontainers import MultiSet | ||
s = MultiSet() | ||
s.insert(1) | ||
s.insert(2) | ||
s.insert(2) | ||
assert list(s) == [1, 2, 2] | ||
assert s.size() == 3 | ||
assert s.count(2) == 2 | ||
assert s.begin().deref() == 1 | ||
``` | ||
|
||
The containers store references to Python objects, not copies. | ||
|
||
``` | ||
from cppcontainers import Vector | ||
from sys import getrefcount | ||
v = Vector() | ||
a = "asd" | ||
b = [1, 2, 3] | ||
v.push_back(a) | ||
v.push_back(b) | ||
assert id(a) == id(v[0]) | ||
assert list(v) == [a, b] | ||
b.append(4) | ||
assert b[-1] == v[1][-1] | ||
assert getrefcount(a) == 3 | ||
del v | ||
assert getrefcount(a) == 2 | ||
``` | ||
|
||
The following crashes, just like in C++. | ||
|
||
``` | ||
from cppcontainers import Vector | ||
Vector()[0] | ||
``` | ||
|
||
And this throws an exception like in C++. | ||
|
||
``` | ||
from cppcontainers import Vector | ||
Vector().at(0) | ||
``` |
Oops, something went wrong.