Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Easy to use Tree Data Structure with many useful methods.
Developed by Tatwik.
We will consider this image as an example for the below code.
from treeds import Tree
tree = Tree(root_nodes=['a'])
- We can have multiple root nodes, Just by passing multiple nodes to the parameter 'root_nodes'
from treeds import Tree
tree = Tree()
tree.add_node(('nil', 'a'))
- Here the parent node of the root node 'a' is 'nil'.
- You can modify the 3rd line of the above code as
tree.add_children('nil', ['a'])
The above function helps to add multiple root nodes instead of one root node 'a'.
# level-1
tree.add_children('a', ['b', 'c', 'd'])
# level-2
tree.add_children('b', ['e', 'f'])
tree.add_children('d', ['g', 'h'])
# level-3
tree.add_children('h', ['i', 'j'])
- Now we have created a Tree that's in the above image.
- Let's print the Tree we have created.
print(tree.tree)
Output:
{'nil': (None, ['a']), 'a': ('nil', ['b', 'c', 'd']), 'b': ('a', ['e', 'f']), 'c': ('a', []), 'd': ('a', ['g', 'h']), 'e': ('b', []), 'f': ('b', []), 'g': ('d', []), 'h': ('d', ['i', 'j']), 'i': ('h', []), 'j': ('h', [])}
Let's check the above Output dictionary.
- Dict Keys - Node names
- Dict Values - (parent node, [child nodes])
Let's see an example: Consider: 'a': ('nil', ['b', 'c', 'd'])
- Here 'a' is the node name.
- 'nil' is the parent node of 'a'.
- ['b', 'c', 'd'] are the children nodes of node 'a'.
Adds the node to the tree.
- parameter node: Tuple with parent and child.
tree.add_node(('parent_node', 'node_name'))
Adds multiple children to the node.
- parameter node: The name of the node.
- parameter children: List of children of the node.
tree.add_children('node_name', ['child_node1', 'child_node2', 'child_node3'])
Returns the parent of the given node.
- parameter node: The name of the node.
- returns: The parent of the given node.
tree.get_parent('b')
Output: 'a'
Returns the list of childeren of the given node.
- parameter node: The name of the node.
- returns: The list of children for the node.
tree.get_children('a')
Output: ['b', 'c', 'd']
Returns The path from root node to the given node.
- parameter node: The name of the node.
- return: The list of path from root node to the given node.
tree.get_path('i')
Output: ['a', 'd', 'h', 'i']
Returns the depth at where the node is located in the tree.
- parameter node: The name of the node.
- return: The depth at which the node is located in the tree.
tree.get_depth('g')
Output: 2
Deletes the node and the tree to the down of the node.
- parameter node: The name of the node.
tree.delete('d')
Because we deleted node 'd' all the nodes below it will also get deleted so the nodes ['d', 'g', 'h', 'i', 'j'] will be deleted.
FAQs
Simple implementation of Tree Data Structure
We found that treeds 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 malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.