LC_COLLATE.
[p5sagit/p5-mst-13.2.git] / hv.h
CommitLineData
a0d0e21e 1/* hv.h
79072805 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, 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 10typedef struct he HE;
11
12struct he {
13 HE *hent_next;
14 char *hent_key;
15 SV *hent_val;
93a17b20 16 U32 hent_hash;
79072805 17 I32 hent_klen;
18};
19
20struct xpvhv {
463ee0b2 21 char * xhv_array; /* pointer to malloced string */
22 STRLEN xhv_fill; /* how full xhv_array currently is */
23 STRLEN xhv_max; /* subscript of last element of xhv_array */
a0d0e21e 24 I32 xhv_keys; /* how many elements in the array */
79072805 25 double xnv_nv; /* numeric value, if any */
26 MAGIC* xmg_magic; /* magic for scalar array */
27 HV* xmg_stash; /* class package */
28
79072805 29 I32 xhv_riter; /* current root of iterator */
30 HE *xhv_eiter; /* current entry of iterator */
31 PMOP *xhv_pmroot; /* list of pm's for this package */
32 char *xhv_name; /* name, if a symbol table */
79072805 33};
34
bf6bd887 35#define PERL_HASH(hash,str,len) \
36 STMT_START { \
37 register char *s_PeRlHaSh = str; \
38 register I32 i_PeRlHaSh = len; \
39 register U32 hash_PeRlHaSh = 0; \
40 while (i_PeRlHaSh--) \
41 hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \
42 (hash) = hash_PeRlHaSh; \
43 } STMT_END
44
45
bf5b86ae 46/* these hash entry flags ride on hent_klen (for use only in magic/tied HVs) */
47#define HEf_SVKEY -2 /* hent_key is a SV* */
bf6bd887 48
49
79072805 50#define Nullhv Null(HV*)
463ee0b2 51#define HvARRAY(hv) ((HE**)((XPVHV*) SvANY(hv))->xhv_array)
79072805 52#define HvFILL(hv) ((XPVHV*) SvANY(hv))->xhv_fill
463ee0b2 53#define HvMAX(hv) ((XPVHV*) SvANY(hv))->xhv_max
54#define HvKEYS(hv) ((XPVHV*) SvANY(hv))->xhv_keys
79072805 55#define HvRITER(hv) ((XPVHV*) SvANY(hv))->xhv_riter
56#define HvEITER(hv) ((XPVHV*) SvANY(hv))->xhv_eiter
57#define HvPMROOT(hv) ((XPVHV*) SvANY(hv))->xhv_pmroot
58#define HvNAME(hv) ((XPVHV*) SvANY(hv))->xhv_name
a0d0e21e 59
bf6bd887 60#define HvSHAREKEYS(hv) (SvFLAGS(hv) & SVphv_SHAREKEYS)
61#define HvSHAREKEYS_on(hv) (SvFLAGS(hv) |= SVphv_SHAREKEYS)
62#define HvSHAREKEYS_off(hv) (SvFLAGS(hv) &= ~SVphv_SHAREKEYS)
63
bf5b86ae 64#define HvLAZYDEL(hv) (SvFLAGS(hv) & SVphv_LAZYDEL)
65#define HvLAZYDEL_on(hv) (SvFLAGS(hv) |= SVphv_LAZYDEL)
66#define HvLAZYDEL_off(hv) (SvFLAGS(hv) &= ~SVphv_LAZYDEL)
67
a0d0e21e 68#ifdef OVERLOAD
69
70/* Maybe amagical: */
71/* #define HV_AMAGICmb(hv) (SvFLAGS(hv) & (SVpgv_badAM | SVpgv_AM)) */
72
73#define HV_AMAGIC(hv) (SvFLAGS(hv) & SVpgv_AM)
74#define HV_AMAGIC_on(hv) (SvFLAGS(hv) |= SVpgv_AM)
75#define HV_AMAGIC_off(hv) (SvFLAGS(hv) &= ~SVpgv_AM)
76
77/*
78#define HV_AMAGICbad(hv) (SvFLAGS(hv) & SVpgv_badAM)
79#define HV_badAMAGIC_on(hv) (SvFLAGS(hv) |= SVpgv_badAM)
80#define HV_badAMAGIC_off(hv) (SvFLAGS(hv) &= ~SVpgv_badAM)
81*/
82
83#endif /* OVERLOAD */
bf6bd887 84
85#define Nullhe Null(HE*)
86#define HeNEXT(he) (he)->hent_next
87#define HeKEY(he) (he)->hent_key
88#define HeKLEN(he) (he)->hent_klen
89#define HeVAL(he) (he)->hent_val
90#define HeHASH(he) (he)->hent_hash
91#define HePV(he) ((he)->hent_klen == HEf_SVKEY) ? \
92 SvPV((SV*)((he)->hent_key),na) : \
93 (he)->hent_key))
94#define HeSVKEY(he) (((he)->hent_key && \
95 (he)->hent_klen == HEf_SVKEY) ? \
96 (SV*)((he)->hent_key) : Nullsv)
97
98#define HeSVKEY_force(he) ((he)->hent_key ? \
99 (((he)->hent_klen == HEf_SVKEY) ? \
100 (SV*)((he)->hent_key) : \
101 sv_2mortal(newSVpv((he)->hent_key, \
102 (he)->hent_klen))) : \
103 &sv_undef)