Metadata-Version: 2.4
Name: dualdict
Version: 0.1.0a2
Summary: Bidirectional mapping with live tuple field proxies
Author: Anjani Agrawal
License: MIT License
        
        Copyright (c) 2026 Anjani
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Author LinkedIn, https://www.linkedin.com/in/anjani-kumar-agrawal/
Keywords: bidirectional,mapping,tuple,live-proxy
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: benchmark
Requires-Dist: bidict==0.24.1; extra == "benchmark"
Dynamic: license-file

# DualDict

Experimental bidirectional mapping with unique keys and values. Live handles follow
a record through endpoint replacement and tuple-field edits. Deleting a record
permanently invalidates its handles, even if its old key is inserted again.

This is an alpha personal project under the MIT License. APIs may change.
Development is intermittent; no support or release schedule is promised.

## Installation

Once this version is published on PyPI:

```sh
python -m pip install dualdict==0.1.0a2
```

The default implementation is pure Python, requires Python 3.10+, and needs no
compiler. Source-build CI exercises Python 3.10, 3.12 and 3.14 on Windows, Linux and
macOS; this is not a claim that every intervening version or platform was tested.

The optional native distribution is installed separately:

```sh
python -m pip install dualdict-cpp==0.3.3a2
```

The initial native wheel targets **Windows x64, GIL-enabled CPython 3.12**. Other
configurations require a source build with a C++17 toolchain and Python development
headers (MSVC Build Tools on Windows). Isolated builds obtain CMake, nanobind and
other declared build dependencies. Source CI covers Windows, Linux and macOS but
does not provide a complete wheel matrix. Native code supports the main interpreter
only; free-threaded Python, PyPy and subinterpreters are unsupported.

## Python example

```python
from dualdict import DualDict

d = DualDict([(101, ("Alice", "Engineering"))])
employee = d.by_key[101]  # live handle
employee[1] = "Research"
assert employee.snapshot() == ("Alice", "Research")
assert d.by_value[("Alice", "Research")].snapshot() == 101
```

## Optional native API

```python
from dualdict.v331_cpp import DualDict

d = DualDict([(101, ("Alice", "Engineering"))])
before = d.by_key[101]  # raw endpoint
employee = d.by_key.live(101)
d.by_key.set_field(101, 1, "Research")
assert before == ("Alice", "Engineering")
assert employee.snapshot() == ("Alice", "Research")
assert d.by_value[("Alice", "Research")] == 101
```

Backend selection is explicit. Installing the native package does not change
`from dualdict import DualDict`. Python indexed reads return live proxies; native
V3.3.1 indexed reads return raw endpoints. `view.snapshot(key)` returns a raw
endpoint in both APIs. Snapshots do not follow replacements and do not copy objects.

## Semantics and limitations

- Both endpoints must be hashable with stable, non-raising, non-reentrant hash and
  equality behavior for their entire stored lifetime, including tuple members.
  Do not externally mutate fields used by hash/equality. Equal objects collide.
- `add` rejects duplicate keys or values, including identical pairs. Assignment
  inserts or replaces an endpoint but rejects another record's endpoint.
- Tuple-field edits require a plain tuple; nested edits, slices and deletion of
  individual fields are excluded. Equal replacement retains the original object.
- Deletion and clear invalidate handles. Handles retain their mapping owner.
- `CollisionError`, `KeyError`, `TypeError` and `DeletedRecordError` report
  collisions, missing lookups, invalid inputs and stale handles respectively.
- Bulk operations commit one entry at a time. Multiple calls are not transactions
  and require application synchronization when shared. Hostile callbacks and
  asynchronous interruption do not have transaction-level guarantees. A native
  owner that cannot restore indexes after rollback failure disables itself and
  must be discarded.
- Average lookup is O(1), excluding hash/equality cost. Tuple edits reconstruct
  and hash an O(width) tuple. Benchmarks are workload-specific; no universal
  speedup, memory saving or production-grade security assurance is claimed.

## Documentation, examples and reproducible benchmarks

The Python **source archive** includes `README.md`, `docs/`, `examples/`, `tests/`
and `benchmarks/`, including benchmark methodology in `benchmarks/README.md`.
These are not installed as runtime modules by the wheel. No public GitHub checkout
is required: download and extract the source archive from this version's package
files, then run these commands from the extracted directory:

```sh
python -m pip install ".[benchmark]"
python -m pip install dualdict-cpp==0.3.3a2
python -m examples.employee_directory
python -m examples.employee_directory --backend v331
python -m benchmarks.bidict_v331 --access random --seed 331
python -m benchmarks.bidict_v331 --access skewed --seed 331
```

Native comparisons require the optional native package and a production build
without allocation-failure hooks. The benchmark extra pins `bidict==0.24.1`.
Reports record environment, configuration, exact timing statements and raw samples.
Random and skewed runs measure different access patterns; results do not establish
application-wide performance. Consult the included methodology before comparing.

## Author

Created by [Anjani Agrawal](https://www.linkedin.com/in/anjani-kumar-agrawal/).
