This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (red-black-tree-typed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
What
Brief
This is a standalone Red Black Tree data structure from the data-structure-typed collection. If you wish to access more data
structures or advanced features, you can transition to directly installing the
complete data-structure-typed package
using Red-Black Tree as a price-based index for stock data
// Define the structure of individual stock recordsinterfaceStockRecord{
price:number;// Stock price (key for indexing)symbol:string;// Stock ticker symbol
volume:number;// Trade volume}// Simulate stock market data as it might come from an external feedconst marketStockData: StockRecord[]=[{ price:142.5,symbol:'AAPL', volume:1000000},{ price:335.2,symbol:'MSFT', volume:800000},{ price:3285.04,symbol:'AMZN', volume:500000},{ price:267.98,symbol:'META', volume:750000},{ price:234.57,symbol:'GOOGL', volume:900000}];// Extend the stock record type to include metadata for database usagetypeStockTableRecord= StockRecord &{ lastUpdated: Date };// Create a Red-Black Tree to index stock records by price// Simulates a database index with stock price as the key for quick lookupsconst priceIndex =newRedBlackTree<number, StockTableRecord, StockRecord>(marketStockData,{toEntryFn: stockRecord =>[
stockRecord.price,// Use stock price as the key{...stockRecord,
lastUpdated:newDate()// Add a timestamp for when the record was indexed}]});// Query the stock with the highest priceconst highestPricedStock = priceIndex.getRightMost();console.log(priceIndex.get(highestPricedStock)?.symbol);// 'AMZN' // Amazon has the highest price// Query stocks within a specific price range (200 to 400)const stocksInRange = priceIndex.rangeSearch([200,400],// Price range
node => priceIndex.get(node)?.symbol// Extract stock symbols for the result);console.log(stocksInRange);// ['GOOGL', 'META', 'MSFT']
Traverse a binary tree in a depth-first manner, starting from the root node, first visiting the left subtree,
and then the right subtree, using recursion.
Recursion + Iteration
Binary Tree BFS
Traverse a binary tree in a breadth-first manner, starting from the root node, visiting nodes level by level
from left to right.
Iteration
Binary Tree Morris
Morris traversal is an in-order traversal algorithm for binary trees with O(1) space complexity. It allows tree
traversal without additional stack or recursion.
Iteration
Software Engineering Design Standards
Principle
Description
Practicality
Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names.
Extensibility
Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures.
Modularization
Includes data structure modularization and independent NPM packages.
Efficiency
All methods provide time and space complexity, comparable to native JS performance.
Maintainability
Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns.
Testability
Automated and customized unit testing, performance testing, and integration testing.
Portability
Plans for porting to Java, Python, and C++, currently achieved to 80%.
Reusability
Fully decoupled, minimized side effects, and adheres to OOP.
Security
Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects.
Scalability
Data structure software does not involve load issues.