MCPcopy Create free account
hub / github.com/hashintel/hash / recursive_structures

Function recursive_structures

libs/@local/hashql/core/src/intern/map.rs:920–986  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

918
919 #[test]
920 fn recursive_structures() {
921 let heap = Heap::new();
922 let map = InternMap::<LinkedList>::new(&heap);
923
924 // Create a linked list using provisioned IDs
925 let node3_id = map.provision();
926 let node3 = map.intern_provisioned(
927 node3_id,
928 PartialLinkedList {
929 value: 3,
930 next_id: None,
931 },
932 );
933
934 let node2_id = map.provision();
935 let node2 = map.intern_provisioned(
936 node2_id,
937 PartialLinkedList {
938 value: 2,
939 next_id: Some(node3.id()),
940 },
941 );
942
943 let node1_id = map.provision();
944 let node1 = map.intern_provisioned(
945 node1_id,
946 PartialLinkedList {
947 value: 1,
948 next_id: Some(node2.id()),
949 },
950 );
951
952 // Verify the links
953 assert_eq!(node1.next_id, Some(node2.id()));
954 assert_eq!(node2.next_id, Some(node3.id()));
955 assert_eq!(node3.next_id, None);
956
957 // Create a similar list but using the closure-based intern method
958 let list = map.intern(|head_id| {
959 // First create the tail node
960 let tail = map.intern_partial(PartialLinkedList {
961 value: 6,
962 next_id: Some(head_id.value()),
963 });
964
965 // Then create the middle node pointing to the tail
966 let middle = map.intern_partial(PartialLinkedList {
967 value: 5,
968 next_id: Some(tail.id()),
969 });
970
971 // Return the head partial that points to the middle
972 PartialLinkedList {
973 value: 4,
974 next_id: Some(middle.id()),
975 }
976 });
977

Callers

nothing calls this directly

Calls 8

intern_partialMethod · 0.80
provisionMethod · 0.45
intern_provisionedMethod · 0.45
idMethod · 0.45
internMethod · 0.45
valueMethod · 0.45
indexMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected