| 1 | package Judy::_obj; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | # Object accessors | ||
| 7 | use constant _ptr => 0; | ||
| 8 | use constant _ptrpath => 1; | ||
| 9 | use constant _type => 2; | ||
| 10 | use constant _fulltype => 3; | ||
| 11 | use constant _innerobj => 4; | ||
| 12 | |||
| 13 | use constant NULL => 0x0; | ||
| 14 | |||
| 15 | use constant _impl => [qw[ _ptr _ptrpath _type _fulltype _innerobj NULL ptr setptr ptrptr ]]; | ||
| 16 | use Sub::Exporter -setup => { | ||
| 17 | groups => { | ||
| 18 | impl => _impl, | ||
| 19 | }, | ||
| 20 | exports => _impl | ||
| 21 | }; | ||
| 22 | |||
| 23 | # 0 for the types and 1, L, '' for the types SL and HS. | ||
| 24 | # | ||
| 25 | sub first_key; | ||
| 26 | |||
| 27 | sub DESTROY {} | ||
| 28 | |||
| 29 | sub ptrptr { | ||
| 30 | for ( $_[0][_ptrpath] ) { | ||
| 31 | return if ! $_; | ||
| 32 | my $container = $_->[0]; | ||
| 33 | my $container_obj = $container->[_innerobj]; | ||
| 34 | my $container_key = $_->[1]; | ||
| 35 | my ( $pval, $val ) = $container_obj->get( $container_key ); | ||
| 36 | #printf "0x%x->ptrptr(0x%x)=0x%x. *0x%4\$x = 0x%x\n", | ||
| 37 | # $container_obj->ptr, | ||
| 38 | # $container_key, | ||
| 39 | # $pval, | ||
| 40 | # $val; | ||
| 41 | return $pval; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | sub setptr { | ||
| 46 | for ( $_[0] ) { | ||
| 47 | if ( $_->[_ptrpath] ) { | ||
| 48 | my ( $pval ) = $_[0]->ptrptr; | ||
| 49 | #printf "*0x%x <- 0x%x\n", $pval, $_[1]; | ||
| 50 | Judy::Mem::Poke( $pval, $_[1] ); | ||
| 51 | return $_[1]; | ||
| 52 | } | ||
| 53 | else { | ||
| 54 | return $_->[_ptr] = $_[1]; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | sub ptr { | ||
| 60 | for ( $_[0] ) { | ||
| 61 | # Sanity check. | ||
| 62 | # | ||
| 63 | if ( $_->[_ptr] && $_->[_ptrpath] ) { | ||
| 64 | my $ptrptr = $_[0]->ptrpr; | ||
| 65 | my $a = Judy::Mem::Peek($ptrptr); | ||
| 66 | my $b = $_->[_ptr]; | ||
| 67 | if ( $a != $b ) { | ||
| 68 | Carp::confess( "\*$a != $b" ); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | if ( $_->[_ptr] ) { | ||
| 73 | return $_->[_ptr]; | ||
| 74 | } | ||
| 75 | elsif ( $_->[_ptrpath] ) { | ||
| 76 | my $ptrptr = $_[0]->ptrptr; | ||
| 77 | return Judy::Mem::Peek( $ptrptr ); | ||
| 78 | } | ||
| 79 | else { | ||
| 80 | return NULL; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | 1; |