Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/arboris_records.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / arboris_records.om` 204 lines ยท 5612 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Compose after arboris_ontology.om. This is a compute projection of StateGraph. 3 note Dense node and edge identities are their row ordinals. The source graph 4 note retains string identity, arbitrary attributes, timestamps and provenance. 5 note Header (uint words): AR01, profile, nodes, edges, max_hops (0 unbounded), 6 note exponential rate bits (finite FP32 in [0,1]). Each node has three words: 7 note type, presence bits for required properties, Running/Stopped flags (bits 0,1). 8 note Each edge has four words: subject, relation, object, conductance FP32 bits. 9 const ar_u32_max ulong 0xffffffff 10 const ar_one uint 0x3f800000 11 const ar_record_v1 uint 0x41523031 12 const ar_topo_v1 uint 0x41525431 13 14 fn ar_records_shape records view uint * to bool 15 if lt len records 6 16 ret false 17 end 18 if ne get records 0 ar_record_v1 19 ret false 20 end 21 profile = get records 1 22 if or lt profile 1 gt profile 2 23 ret false 24 end 25 n = ulong get records 2 26 e = ulong get records 3 27 if or eq n 0 gt e div ar_u32_max 2 28 ret false 29 end 30 if gt get records 5 ar_one 31 ret false 32 end 33 ret eq len records add 6 add mul n 3 mul e 4 34 end 35 36 fn ar_nodes_ok r view uint * to bool 37 for i ulong ulong get r 2 bound ar_u32_max 38 pos = add 6 mul i 3 39 if not arboris_node_ok ulong get r 1 ulong get r pos get r add pos 1 get r add pos 2 40 ret false 41 end 42 end 43 ret true 44 end 45 46 fn ar_edge_record_ok r view uint * pos ulong to bool 47 n = ulong get r 2 48 src = ulong get r pos 49 dst = ulong get r add pos 2 50 if or ge src n ge dst n 51 ret false 52 end 53 kind_src = ulong get r add 6 mul src 3 54 kind_dst = ulong get r add 6 mul dst 3 55 if not arboris_edge_ok ulong get r 1 ulong get r add pos 1 kind_src kind_dst 56 ret false 57 end 58 bits = get r add pos 3 59 if gt bits ar_one 60 ret false 61 end 62 note Incident-edge traversal permits a two-hop return along every edge. 63 if eq get r 4 0 64 if and eq bits ar_one eq get r 5 ar_one 65 ret false 66 end 67 end 68 ret true 69 end 70 71 fn ar_insert topo edit uint * weights edit uint * endpoints ulong w uint to void 72 slot = add 3 shr endpoints 32 73 ix = get topo slot 74 first = add 4 ulong get topo 1 75 put topo add first ulong ix uint and endpoints ar_u32_max 76 put weights ulong ix w 77 put topo slot add ix 1 78 end 79 80 fn ar_row_starts r view uint * topo edit uint * to void 81 n = ulong get r 2 82 e = ulong get r 3 83 edges = add 6 mul n 3 84 put topo 0 ar_topo_v1 85 put topo 1 uint n 86 put topo 2 uint mul e 2 87 put topo add 3 n uint mul e 2 88 for i ulong n bound ar_u32_max 89 put topo add 3 i 0 90 end 91 for i ulong e bound ar_u32_max 92 pos = add edges mul i 4 93 src_slot = add 3 ulong get r pos 94 dst_slot = add 3 ulong get r add pos 2 95 put topo src_slot add get topo src_slot 1 96 put topo dst_slot add get topo dst_slot 1 97 end 98 cursor = uint 0 99 for v ulong n bound ar_u32_max 100 slot = add 3 v 101 count = get topo slot 102 put topo slot cursor 103 cursor = add cursor count 104 end 105 end 106 107 fn ar_scatter r view uint * topo edit uint * weights edit uint * to void 108 pos = add 6 mul ulong get r 2 3 109 while lt pos len r bound ar_u32_max 110 pair = or shl ulong get r pos 32 ulong get r add pos 2 111 w = get r add pos 3 112 ar_insert topo weights pair w 113 ar_insert topo weights rotl pair 32 w 114 pos = add pos 4 115 end 116 end 117 118 fn ar_validate_records r view uint * topology_len ulong param_len ulong to ulong 119 if not ar_records_shape r 120 ret 1 121 end 122 n = ulong get r 2 123 e = ulong get r 3 124 if or ne topology_len add add n 4 mul e 2 ne param_len mul e 2 125 ret 2 126 end 127 if not ar_nodes_ok r 128 ret 3 129 end 130 edges = add 6 mul n 3 131 for i ulong e bound ar_u32_max 132 if not ar_edge_record_ok r add edges mul i 4 133 ret 4 134 end 135 end 136 ret 0 137 end 138 139 fn ar_restore_rows topo edit uint * to void 140 n = ulong get topo 1 141 note The cursors now point to each row end. Restore row starts, in reverse. 142 for i ulong n bound ar_u32_max 143 slot = add 3 sub n i 144 put topo slot get topo sub slot 1 145 end 146 put topo 3 0 147 end 148 149 note Output TopologyCSR words: ART1, node count, arc count, N+1 offsets, 150 note then arc source handles. ParamSlab holds one conductance word per arc. 151 note Verify all input and output extents before the first write. 152 export fn arboris_load_records r view uint * topo edit uint * weights edit uint * to ulong 153 reason = ar_validate_records r len topo len weights 154 if ne reason 0 155 ret reason 156 end 157 ar_row_starts r topo 158 ar_scatter r topo weights 159 ar_restore_rows topo 160 ret 0 161 end 162 163 note Digest the versioned CSR and parallel conductances in little-endian wire 164 note order. ART1 and the N/A counts frame the two arrays unambiguously. 165 fn ar_hash_words ctx edit ulong 40 data view uint * to void 166 block = new uchar 64 0 167 used = ulong 0 168 for i ulong len data bound 0x7fffffffffffffff 169 word = get data i 170 put block used uchar and word 255 171 put block add used 1 uchar and shr word 8 255 172 put block add used 2 uchar and shr word 16 255 173 put block add used 3 uchar shr word 24 174 used = add used 4 175 if eq used 64 176 sha256_update ctx block 177 used = ulong 0 178 end 179 end 180 if ne used 0 181 sha256_update ctx part block 0 used 182 end 183 end 184 185 export fn arboris_topology_digest topo view uint * weights view uint * digest edit uchar 32 to ulong 186 if lt len topo 4 187 ret 1 188 end 189 if ne get topo 0 ar_topo_v1 190 ret 1 191 end 192 if ne len weights ulong get topo 2 193 ret 1 194 end 195 if ne len topo add 4 add ulong get topo 1 len weights 196 ret 1 197 end 198 ctx = new ulong 40 0 199 sha256_init ctx 200 ar_hash_words ctx topo 201 ar_hash_words ctx weights 202 sha256_final ctx digest 203 ret 0 204 end