A thread safe implementation of the SortedDict.
Project description
Contradict
Description
Contradict provides a thread-safe implementation of the SortedDict. The SortedDict exposes exposes APIs for the following operationsget
, set
, contains
, items
, keys
and value
.
Object Usage
For adding an object to the SortedDict, the object needs to implement it's comparator logic and hash function.
class GitRepo:
def __init__(self, url, stars, forks):
self.url = url
self.stars = stars
self.forks = forks
# The object needs to implement the following methods
def __eq__(self, other):
return self.name == other.name and self.stars == other.stars and self.forks == other.forks
def __ne__(self, other):
return self.name != other.name or self.stars != other.stars or self.forks != other.forks
def __lt__(self, other):
# The two repos are first compared based on stars then forks and then sorted lexically based on url
if self.stars == other.stars and self.forks == other.forks return self.url < other.url
def __le__(self, other):
if self.stars == other.stars and self.forks == other.forks return self.url <= other.url
def __gt__(self, other):
if self.stars == other.stars and self.forks == other.forks return self.url > other.url
def __ge__(self, other):
if self.stars == other.stars and self.forks == other.forks return self.url >= other.url
# Use any unique attribute to hash
def __hash__(self):
return hash(self.url)
Dependencies
Python 3
Installation
pip install --upgrade contradict
Usage
from contradict.sorted_dict import SortedDict
sorted_dict = SortedDict() # Creates an empty MaxHeap
sorted_dict.set(key, value) # Sets a key, value pair
sorted_dict.get(key) # Returns the value, if key is present or None
sorted_dict.items() # Returns an interator to the key, value pairs in asc order
sorted_dict.keys() # Returns an interator to the keys in asc order
sorted_dict.values() # Returns an interator to the values in asc order of keys
sorted_dict.items(reverse=True) # Returns an interator to the key, value pairs in desc order
sorted_dict.keys(reverse=True) # Returns an interator to the keys in desc order
sorted_dict.values(reverse=True) # Returns an interator to the values in desc order of keys
License
MIT
Changelog
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Contradict-1.0.0.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for Contradict-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34ffb08824a2429d1a3f45fe7b8212312538aaceaa1a0de85039e6f757f48cab |
|
MD5 | 557d5aad86b2fdebd9632b2502714b7f |
|
BLAKE2b-256 | f243f2c86b961c07d6be9122e323092747f8fab8b128f35b465d58101b30eef2 |