Skip to content
Pritam Kundu edited this page Aug 3, 2023 · 8 revisions

Introduction

  • A node is a fundamental data block which for storage.
  • It is a self-referential data structures which uses pointer internally to reference its next item.
  • Used with data-structures like Lists, preferably LinkedLists
  • It is a basic unit block and can hold any data type along with a reference to its next Node.

Usage

from datastax.Nodes import Node

1.1 Method signatures and Class Hierarchy

class Node(AbstractNode):
    data: Any
    def __init__(self, data: Any, _next: Optional[Self] = None) -> None: ...
    def set_next(self, _next: Optional[Self]): ...

1.2 Constructor

  • Takes 1 required parameter data of Any type
  • Takes 1 optional parameter _next of Node type to reference next node
Node(10) # ✅
Node(None) # ✅
Node("string") # ✅
Node(10, None) # ✅
Node(None, None) # ✅
Node(10, Node(20)) # ✅
Node(data=10, _next=Node(20)) # ✅
Node(10, _next=None) # ✅
Node(_next=None, data=10) # ✅

Node() # ❌ TypeError: Node missing 1 required positional argument: 'data'
Node(10, 20) # ❌ TypeError: The 'next' parameter must be an instance of Node
Node(_next=10) # ❌ TypeError: Node missing 1 required positional argument: 'data'