code wiki / _hdl_build / nx_connect_graph_lib.nx

nx_connect_graph_lib.nx source

↩ module page · 69 lines · 3394 B

1// nx_connect_graph_lib.nx -- THE UNIFIED INTEREST GRAPH, extracted as a shared library so the verifying 2// gate (nx_connect_graph) and the front door (nx_connect_api, verb `graph`) bind ONE implementation. 3// This is CONNECT's whole thesis in one function: language, hobby, faith and place live on a SINGLE 4// heterogeneous-information-network model, scored per intent lane, so two people with no shared language 5// but a shared hobby and belief still find each other in the friendship lane -- the apps that silo these 6// miss them. Faith is CONSENT-gated (GDPR Art.9), and the minor<->romance wall is preserved by construction. 7// Symbols carry a gx_ prefix (no bare collisions with the other engine libs). No main, no shared state. 8// license_tier: ORIGINAL 9 10const GX_LANE_LANG: i64 = 0 11const GX_LANE_FRIEND: i64 = 1 12const GX_LANE_COMMUNITY: i64 = 2 13const GX_LANE_DATE: i64 = 3 14const GX_BAND_MINOR: i64 = 0 15const GX_BAND_ADULT: i64 = 1 16const GX_EXCLUDED: i64 = 0-1 17const GX_NODE_SLOTS: i64 = 8 // p[0..6] used; slot count for callers allocating a node 18 19func gx_inter_popc(a: i64, b: i64) -> i64 { 20 var c: i64=0 21 var x: i64=a 22 var y: i64=b 23 while x>0 { 24 let ax: i64 = x - (x/2)*2 25 let by: i64 = y - (y/2)*2 26 if ax==1 { if by==1 { c=c+1 } } 27 x=x/2; y=y/2 28 } 29 return c 30} 31func gx_clamp100(v: i64) -> i64 { if v>100 { return 100 } return v } 32func gx_hm(a: i64, b: i64) -> i64 { if a==0 { return 0 } if b==0 { return 0 } return (2*a*b)/(a+b) } 33 34// person node: p[0]=age_band p[1]=teach p[2]=learn p[3]=hobbies p[4]=faith p[5]=faith_optin p[6]=place 35// fills a CALLER-SUPPLIED slot (no allocation -> no syscall dependency). 36func gx_mk(p: *i64, band: i64, teach: i64, learn: i64, hob: i64, faith: i64, optin: i64, place: i64) -> i64 { 37 p[0]=band; p[1]=teach; p[2]=learn; p[3]=hob; p[4]=faith; p[5]=optin; p[6]=place 38 return 0 39} 40 41// meta-path: reciprocal language (the R1 path) -- harmonic mean of both teach/learn directions. 42func gx_mp_lang(a: *i64, b: *i64) -> i64 { 43 let ab: i64 = gx_inter_popc(a[2], b[1]) 44 let ba: i64 = gx_inter_popc(b[2], a[1]) 45 return gx_hm(gx_clamp100(ab*50), gx_clamp100(ba*50)) 46} 47// meta-path: shared faith -- CONSENT-gated (both must opt into faith discovery; "none"=0 never matches). 48func gx_mp_faith(af: i64, ao: i64, bf: i64, bo: i64) -> i64 { 49 if ao==1 { if bo==1 { if af==bf { if af!=0 { return 100 } } } } 50 return 0 51} 52 53// ONE model, LANE-parameterized, over all meta-paths. Returns GX_EXCLUDED(<0) or 0..100. 54func gx_graph_score(a: *i64, b: *i64, lane: i64) -> i64 { 55 if lane==GX_LANE_DATE { if a[0]==GX_BAND_MINOR { return GX_EXCLUDED } } // safety wall preserved 56 if lane==GX_LANE_DATE { if b[0]==GX_BAND_MINOR { return GX_EXCLUDED } } 57 let lng: i64 = gx_mp_lang(a, b) 58 let hob: i64 = gx_clamp100(gx_inter_popc(a[3], b[3])*34) 59 let fth: i64 = gx_mp_faith(a[4], a[5], b[4], b[5]) 60 var plc: i64 = 0 61 if a[6]==b[6] { plc = 100 } 62 if lane==GX_LANE_LANG { // language lane: reciprocal language NECESSARY (generalizes R1) 63 if lng==0 { return 0 } 64 return (lng*70 + hob*30)/100 65 } 66 var s: i64 = (hob*50 + fth*30 + plc*20)/100 // friendship/community/dating: language NOT required 67 if lng>0 { s = s + 10 } // shared language is a bonus, not a gate 68 return gx_clamp100(s) 69}