
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
A pure Python implementation of a Red-Black Tree, a self-balancing binary search tree. This data structure provides efficient insertion, deletion, and search operations in O(log n) time complexity.
insert
, delete
, search
, minimum
, maximum
all operate in O(log n) time.len()
, in
, []
(getitem), []=
(setitem), del []
(delitem).You can install the package directly from PyPI (once published):
pip install rbtree-py
Or, install directly from the source repository:
pip install git+https://github.com/manyan-chan/rbtree-py.git
For local development, clone the repository and install in editable mode:
git clone https://github.com/manyan-chan/rbtree-py.git
cd rbtree-py
pip install -e .[test]
Here's a basic example of how to use the RedBlackTree
:
from redblacktree import RedBlackTree
# Create a new tree
rbt = RedBlackTree[int, str]() # Specify key and value types (optional but recommended)
# Insert key-value pairs (like a dictionary)
rbt[10] = "Apple"
rbt[5] = "Banana"
rbt[15] = "Cherry"
rbt[3] = "Date"
rbt[7] = "Elderberry"
rbt[12] = "Fig"
rbt[18] = "Grape"
# Check length
print(f"Tree size: {len(rbt)}") # Output: Tree size: 7
# Check if a key exists
print(f"Has key 7? {7 in rbt}") # Output: Has key 7? True
print(f"Has key 99? {99 in rbt}") # Output: Has key 99? False
# Get value by key
print(f"Value for key 15: {rbt[15]}") # Output: Value for key 15: Cherry
# Attempt to get non-existent key (raises KeyError)
try:
print(rbt[99])
except KeyError as e:
print(e) # Output: 'Key not found: 99'
# Update value
rbt[5] = "Blueberry"
print(f"Updated value for key 5: {rbt[5]}") # Output: Updated value for key 5: Blueberry
# Delete a key
del rbt[12]
print(f"Tree size after deleting 12: {len(rbt)}") # Output: Tree size after deleting 12: 6
print(f"Has key 12? {12 in rbt}") # Output: Has key 12? False
# Iterate over keys (sorted order)
print("Keys:", list(rbt)) # Output: Keys: [3, 5, 7, 10, 15, 18]
# Iterate over values (sorted by key)
print("Values:", list(rbt.values())) # Output: Values: ['Date', 'Blueberry', 'Elderberry', 'Apple', 'Cherry', 'Grape']
# Iterate over items (key, value) pairs (sorted by key)
print("Items:", list(rbt.items()))
# Output: Items: [(3, 'Date'), (5, 'Blueberry'), (7, 'Elderberry'), (10, 'Apple'), (15, 'Cherry'), (18, 'Grape')]
# Find minimum and maximum keys
min_node = rbt.minimum()
max_node = rbt.maximum()
if min_node is not rbt.nil: # Check if tree is not empty
print(f"Minimum key: {min_node.key}, Value: {min_node.value}")
if max_node is not rbt.nil:
print(f"Maximum key: {max_node.key}, Value: {max_node.value}")
# Output:
# Minimum key: 3, Value: Date
# Maximum key: 18, Value: Grape
# Print tree structure (for debugging)
# print("\nTree Structure:")
# rbt.print_tree() # Optional: Visualize the tree structure
The package uses pytest
for testing. To run the tests:
pip install -e .[test]
pytest
Contributions are welcome! Please feel free to submit issues or pull requests.
git checkout -b feature/your-feature-name
).pytest
).black
or flake8
).git commit -am 'Add some feature'
).git push origin feature/your-feature-name
).This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A Python implementation of a Red-Black Tree data structure.
We found that rbtree-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.