Commit | Line | Data |
a0d0e21e |
1 | /* hv.h |
79072805 |
2 | * |
9607fc9c |
3 | * Copyright (c) 1991-1997, Larry Wall |
79072805 |
4 | * |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
7 | * |
79072805 |
8 | */ |
9 | |
79072805 |
10 | typedef struct he HE; |
ff68c719 |
11 | typedef struct hek HEK; |
79072805 |
12 | |
13 | struct he { |
14 | HE *hent_next; |
ff68c719 |
15 | HEK *hent_hek; |
79072805 |
16 | SV *hent_val; |
bbce6d69 |
17 | }; |
18 | |
ff68c719 |
19 | struct hek { |
20 | U32 hek_hash; |
21 | I32 hek_len; |
22 | char hek_key[1]; |
79072805 |
23 | }; |
24 | |
6ee623d5 |
25 | /* This structure must match the beginning of struct xpvmg in sv.h. */ |
79072805 |
26 | struct xpvhv { |
463ee0b2 |
27 | char * xhv_array; /* pointer to malloced string */ |
28 | STRLEN xhv_fill; /* how full xhv_array currently is */ |
29 | STRLEN xhv_max; /* subscript of last element of xhv_array */ |
6ee623d5 |
30 | IV xhv_keys; /* how many elements in the array */ |
79072805 |
31 | double xnv_nv; /* numeric value, if any */ |
32 | MAGIC* xmg_magic; /* magic for scalar array */ |
33 | HV* xmg_stash; /* class package */ |
34 | |
79072805 |
35 | I32 xhv_riter; /* current root of iterator */ |
36 | HE *xhv_eiter; /* current entry of iterator */ |
37 | PMOP *xhv_pmroot; /* list of pm's for this package */ |
38 | char *xhv_name; /* name, if a symbol table */ |
79072805 |
39 | }; |
40 | |
bf6bd887 |
41 | #define PERL_HASH(hash,str,len) \ |
42 | STMT_START { \ |
08105a92 |
43 | register const char *s_PeRlHaSh = str; \ |
bf6bd887 |
44 | register I32 i_PeRlHaSh = len; \ |
45 | register U32 hash_PeRlHaSh = 0; \ |
46 | while (i_PeRlHaSh--) \ |
47 | hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ |
8ac04967 |
48 | (hash) = hash_PeRlHaSh + (hash_PeRlHaSh>>5); \ |
bf6bd887 |
49 | } STMT_END |
50 | |
51 | |
bf5b86ae |
52 | /* these hash entry flags ride on hent_klen (for use only in magic/tied HVs) */ |
53 | #define HEf_SVKEY -2 /* hent_key is a SV* */ |
bf6bd887 |
54 | |
55 | |
79072805 |
56 | #define Nullhv Null(HV*) |
463ee0b2 |
57 | #define HvARRAY(hv) ((HE**)((XPVHV*) SvANY(hv))->xhv_array) |
79072805 |
58 | #define HvFILL(hv) ((XPVHV*) SvANY(hv))->xhv_fill |
463ee0b2 |
59 | #define HvMAX(hv) ((XPVHV*) SvANY(hv))->xhv_max |
60 | #define HvKEYS(hv) ((XPVHV*) SvANY(hv))->xhv_keys |
79072805 |
61 | #define HvRITER(hv) ((XPVHV*) SvANY(hv))->xhv_riter |
62 | #define HvEITER(hv) ((XPVHV*) SvANY(hv))->xhv_eiter |
63 | #define HvPMROOT(hv) ((XPVHV*) SvANY(hv))->xhv_pmroot |
64 | #define HvNAME(hv) ((XPVHV*) SvANY(hv))->xhv_name |
a0d0e21e |
65 | |
bf6bd887 |
66 | #define HvSHAREKEYS(hv) (SvFLAGS(hv) & SVphv_SHAREKEYS) |
67 | #define HvSHAREKEYS_on(hv) (SvFLAGS(hv) |= SVphv_SHAREKEYS) |
68 | #define HvSHAREKEYS_off(hv) (SvFLAGS(hv) &= ~SVphv_SHAREKEYS) |
69 | |
bf5b86ae |
70 | #define HvLAZYDEL(hv) (SvFLAGS(hv) & SVphv_LAZYDEL) |
71 | #define HvLAZYDEL_on(hv) (SvFLAGS(hv) |= SVphv_LAZYDEL) |
72 | #define HvLAZYDEL_off(hv) (SvFLAGS(hv) &= ~SVphv_LAZYDEL) |
73 | |
a0d0e21e |
74 | /* Maybe amagical: */ |
75 | /* #define HV_AMAGICmb(hv) (SvFLAGS(hv) & (SVpgv_badAM | SVpgv_AM)) */ |
76 | |
77 | #define HV_AMAGIC(hv) (SvFLAGS(hv) & SVpgv_AM) |
78 | #define HV_AMAGIC_on(hv) (SvFLAGS(hv) |= SVpgv_AM) |
79 | #define HV_AMAGIC_off(hv) (SvFLAGS(hv) &= ~SVpgv_AM) |
80 | |
81 | /* |
82 | #define HV_AMAGICbad(hv) (SvFLAGS(hv) & SVpgv_badAM) |
83 | #define HV_badAMAGIC_on(hv) (SvFLAGS(hv) |= SVpgv_badAM) |
84 | #define HV_badAMAGIC_off(hv) (SvFLAGS(hv) &= ~SVpgv_badAM) |
85 | */ |
bf6bd887 |
86 | |
87 | #define Nullhe Null(HE*) |
88 | #define HeNEXT(he) (he)->hent_next |
ff68c719 |
89 | #define HeKEY_hek(he) (he)->hent_hek |
90 | #define HeKEY(he) HEK_KEY(HeKEY_hek(he)) |
bbce6d69 |
91 | #define HeKEY_sv(he) (*(SV**)HeKEY(he)) |
ff68c719 |
92 | #define HeKLEN(he) HEK_LEN(HeKEY_hek(he)) |
bf6bd887 |
93 | #define HeVAL(he) (he)->hent_val |
ff68c719 |
94 | #define HeHASH(he) HEK_HASH(HeKEY_hek(he)) |
1e422769 |
95 | #define HePV(he,lp) ((HeKLEN(he) == HEf_SVKEY) ? \ |
96 | SvPV(HeKEY_sv(he),lp) : \ |
97 | (((lp = HeKLEN(he)) >= 0) ? \ |
98 | HeKEY(he) : Nullch)) |
99 | |
bbce6d69 |
100 | #define HeSVKEY(he) ((HeKEY(he) && \ |
101 | HeKLEN(he) == HEf_SVKEY) ? \ |
102 | HeKEY_sv(he) : Nullsv) |
103 | |
104 | #define HeSVKEY_force(he) (HeKEY(he) ? \ |
105 | ((HeKLEN(he) == HEf_SVKEY) ? \ |
106 | HeKEY_sv(he) : \ |
107 | sv_2mortal(newSVpv(HeKEY(he), \ |
108 | HeKLEN(he)))) : \ |
3280af22 |
109 | &PL_sv_undef) |
1e422769 |
110 | #define HeSVKEY_set(he,sv) ((HeKLEN(he) = HEf_SVKEY), (HeKEY_sv(he) = sv)) |
bbce6d69 |
111 | |
ff68c719 |
112 | #define Nullhek Null(HEK*) |
71be2cbc |
113 | #define HEK_BASESIZE STRUCT_OFFSET(HEK, hek_key[0]) |
ff68c719 |
114 | #define HEK_HASH(hek) (hek)->hek_hash |
115 | #define HEK_LEN(hek) (hek)->hek_len |
116 | #define HEK_KEY(hek) (hek)->hek_key |