Is there a way to load a memory-only pointer type

I’m trying to write a solution to a problem I found online using Mojo. The problem is a graph theory related so I wanted to implement the data structure by hand to get more familiar with the language.

from memory import Pointer
from collections import List

struct NodeEdge:
    var node1P: Pointer[Node] 
    var node2P: Pointer[Node]
    var edgeWeight: UInt16 

    fn __init__(inout self, inout node1: Node, inout node2: Node, weight: UInt16) -> NoneType:
        self.node1P = Pointer[Node].address_of(node1)
        self.node2P = Pointer[Node].address_of(node2)
        self.edgeWeight = weight
        node1.addEdge(self)
        node2.addEdge(self)

    fn __copyinit__(inout self, node1: NodeEdge) -> NoneType:
        self.node1P = node1.node1P
        self.node2P = node1.node2P
        self.edgeWeight = node1.edgeWeight

    fn __moveinit__(inout self, owned node1: NodeEdge) -> NoneType:
        self.node1P = node1.node1P
        self.node2P = node1.node2P
        self.edgeWeight = node1.edgeWeight


struct Node:
    var nodeType: String
    var nodeData: List[UInt16]
    var nodeEdges: List[NodeEdge]

    fn __init__(inout self) -> NoneType:
        self.nodeType = ''
        self.nodeData = List[UInt16]()
        self.nodeEdges = List[NodeEdge]()
        

    fn __init__(inout self, ntype: String, data: List[UInt16], edges: List[NodeEdge]) -> NoneType:
        self.nodeType = ntype
        self.nodeData = data
        self.nodeEdges = edges

    fn addEdge(inout self, edge: NodeEdge) -> NoneType:
        self.nodeEdges.append(edge)

    fn setNodeType(inout self, ntype: String) -> NoneType:
        self.nodeType = ntype

    fn setNodeData(inout self, data: List[UInt16]) -> NoneType:
        self.nodeData = data

    fn setNodeEdgeData(inout self, data: List[NodeEdge]) -> NoneType:
        self.nodeEdges = data

    fn printNode(inout self) -> String:
        var res: String
        res = self.nodeType + "n"
        for i in range(self.nodeData.size):
            res.__iadd__(self.nodeData[i])
            res.__iadd__(" ")
        res.__iadd__("n")

        for i in range(self.nodeEdges.size):
            res.__iadd__(self.nodeEdges[i].edgeWeight)
            res.__iadd__(" ")
        res.__iadd__("n")
        return res

    fn printFirstEdgeNode(inout self) -> String:
        var res: String
        var firstNodeEdge = self.nodeEdges[0]
        var pSelf = Pointer[Node].address_of(self)
        if (pSelf.__eq__(firstNodeEdge.node1P)):
            #ERROR Occurrs here 
            var nodeToPrint = firstNodeEdge.node2P.load()
        else: 
            #print other node
            pass
        return ''




fn main():
    var node1 = Node()
    var ndata1: List[UInt16]
    
    var node2 = Node()
    var ndata2: List[UInt16]

    ndata1 = List[UInt16](17)
    ndata2 = List[UInt16](12,2)
    node1.setNodeType("Sum")
    node2.setNodeType("Path")
    node1.setNodeData(ndata1)
    node2.setNodeData(ndata2)

    createEdges(node1, node2)
    print(node1.printFirstEdgeNode())


fn createEdges(inout node1: Node, inout node2: Node) -> NoneType:
    var edge = NodeEdge(node1, node2, 5)

I want the function printFirstEdgeNode to be able to look at its list of edge nodes and select the first one and print that node using the printNode function. The problem I’m encountering is in trying to load the pointer from the list of edges. Since each edge has a link to the nodes its connecting, I figure if I was able to load the Node object from that pointer then call the print node function on that object I could get the result I want, but I’m thinking that since it’s a memory-only struct I’m not going to be able to do it like this. Is there a similar way to accomplish this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật