File: Tie%3A%3AIxHash.3pm

package info (click to toggle)
libtie-ixhash-perl 1.21-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge, squeeze, wheezy
  • size: 104 kB
  • ctags: 214
  • sloc: makefile: 433; perl: 330
file content (319 lines) | stat: -rw-r--r-- 10,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
.\" Automatically generated by Pod::Man version 1.16
.\" Tue Aug  7 19:04:44 2001
.\"
.\" Standard preamble:
.\" ======================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Ip \" List item
.br
.ie \\n(.$>=3 .ne \\$3
.el .ne 3
.IP "\\$1" \\$2
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R

.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used
.\" to do unbreakable dashes and therefore won't be available.  \*(C` and
.\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr
.\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
.\" index entries marked with X<> in POD.  Of course, you'll have to process
.\" the output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it
.\" makes way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.bd B 3
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ======================================================================
.\"
.IX Title "Tie::IxHash 3"
.TH Tie::IxHash 3 "perl v5.6.1" "1997-11-20" "User Contributed Perl Documentation"
.UC
.SH "NAME"
Tie::IxHash \- ordered associative arrays for Perl
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 3
\&    # simple usage
\&    use Tie::IxHash;
\&    tie HASHVARIABLE, Tie::IxHash [, LIST];
.Ve
.Vb 17
\&    # OO interface with more powerful features
\&    use Tie::IxHash;
\&    TIEOBJECT = Tie::IxHash->new( [LIST] );
\&    TIEOBJECT->Splice( OFFSET [, LENGTH [, LIST]] );
\&    TIEOBJECT->Push( LIST );
\&    TIEOBJECT->Pop;
\&    TIEOBJECT->Shift;
\&    TIEOBJECT->Unshift( LIST );
\&    TIEOBJECT->Keys( [LIST] );
\&    TIEOBJECT->Values( [LIST] );
\&    TIEOBJECT->Indices( LIST );
\&    TIEOBJECT->Delete( [LIST] );
\&    TIEOBJECT->Replace( OFFSET, VALUE, [KEY] );
\&    TIEOBJECT->Reorder( LIST );
\&    TIEOBJECT->SortByKey;
\&    TIEOBJECT->SortByValue;
\&    TIEOBJECT->Length;
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This Perl module implements Perl hashes that preserve the order in which the
hash elements were added.  The order is not affected when values
corresponding to existing keys in the IxHash are changed.  The elements can
also be set to any arbitrary supplied order.  The familiar perl array
operations can also be performed on the IxHash.
.if n .Sh "Standard \f(CW""TIEHASH""\fP Interface"
.el .Sh "Standard \f(CWTIEHASH\fP Interface"
.IX Subsection "Standard TIEHASH Interface"
The standard \f(CW\*(C`TIEHASH\*(C'\fR mechanism is available. This interface is 
recommended for simple uses, since the usage is exactly the same as
regular Perl hashes after the \f(CW\*(C`tie\*(C'\fR is declared.
.Sh "Object Interface"
.IX Subsection "Object Interface"
This module also provides an extended object-oriented interface that can be
used for more powerful operations with the IxHash.  The following methods
are available:
.Ip "\s-1FETCH\s0, \s-1STORE\s0, \s-1DELETE\s0, \s-1EXISTS\s0" 8
.IX Item "FETCH, STORE, DELETE, EXISTS"
These standard \f(CW\*(C`TIEHASH\*(C'\fR methods mandated by Perl can be used directly.
See the \f(CW\*(C`tie\*(C'\fR entry in \fIperlfunc\fR\|(1) for details.
.Ip "Push, Pop, Shift, Unshift, Splice" 8
.IX Item "Push, Pop, Shift, Unshift, Splice"
These additional methods resembling Perl functions are available for
operating on key-value pairs in the IxHash. The behavior is the same as the
corresponding perl functions, except when a supplied hash key already exists
in the hash. In that case, the existing value is updated but its order is
not affected.  To unconditionally alter the order of a supplied key-value
pair, first \f(CW\*(C`DELETE\*(C'\fR the IxHash element.
.Ip "Keys" 8
.IX Item "Keys"
Returns an array of IxHash element keys corresponding to the list of supplied
indices.  Returns an array of all the keys if called without arguments.
Note the return value is mostly only useful when used in a list context
(since perl will convert it to the number of elements in the array when
used in a scalar context, and that may not be very useful).
.Sp
If a single argument is given, returns the single key corresponding to
the index.  This is usable in either scalar or list context.
.Ip "Values" 8
.IX Item "Values"
Returns an array of IxHash element values corresponding to the list of supplied
indices.  Returns an array of all the values if called without arguments.
Note the return value is mostly only useful when used in a list context
(since perl will convert it to the number of elements in the array when
used in a scalar context, and that may not be very useful).
.Sp
If a single argument is given, returns the single value corresponding to
the index.  This is usable in either scalar or list context.
.Ip "Indices" 8
.IX Item "Indices"
Returns an array of indices corresponding to the supplied list of keys.
Note the return value is mostly only useful when used in a list context
(since perl will convert it to the number of elements in the array when
used in a scalar context, and that may not be very useful).
.Sp
If a single argument is given, returns the single index corresponding to
the key.  This is usable in either scalar or list context.
.Ip "Delete" 8
.IX Item "Delete"
Removes elements with the supplied keys from the IxHash.
.Ip "Replace" 8
.IX Item "Replace"
Substitutes the IxHash element at the specified index with the supplied
value-key pair.  If a key is not supplied, simply substitutes the value at
index with the supplied value. If an element with the supplied key already
exists, it will be removed from the IxHash first.
.Ip "Reorder" 8
.IX Item "Reorder"
This method can be used to manipulate the internal order of the IxHash
elements by supplying a list of keys in the desired order.  Note however,
that any IxHash elements whose keys are not in the list will be removed from
the IxHash.
.Ip "Length" 8
.IX Item "Length"
Returns the number of IxHash elements.
.Ip "SortByKey" 8
.IX Item "SortByKey"
Reorders the IxHash elements by textual comparison of the keys.
.Ip "SortByValue" 8
.IX Item "SortByValue"
Reorders the IxHash elements by textual comparison of the values.
.SH "EXAMPLE"
.IX Header "EXAMPLE"
.Vb 1
\&    use Tie::IxHash;
.Ve
.Vb 7
\&    # simple interface
\&    $t = tie(%myhash, Tie::IxHash, 'a' => 1, 'b' => 2);
\&    %myhash = (first => 1, second => 2, third => 3);
\&    $myhash{fourth} = 4;
\&    @keys = keys %myhash;
\&    @values = values %myhash;
\&    print("y") if exists $myhash{third};
.Ve
.Vb 7
\&    # OO interface
\&    $t = Tie::IxHash->new(first => 1, second => 2, third => 3);
\&    $t->Push(fourth => 4); # same as $myhash{'fourth'} = 4;
\&    ($k, $v) = $t->Pop;    # $k is 'fourth', $v is 4
\&    $t->Unshift(neg => -1, zeroth => 0); 
\&    ($k, $v) = $t->Shift;  # $k is 'neg', $v is -1
\&    @oneandtwo = $t->Splice(1, 2, foo => 100, bar => 101);
.Ve
.Vb 8
\&    @keys = $t->Keys;
\&    @values = $t->Values;
\&    @indices = $t->Indices('foo', 'zeroth');
\&    @itemkeys = $t->Keys(@indices);
\&    @itemvals = $t->Values(@indices);
\&    $t->Replace(2, 0.3, 'other');
\&    $t->Delete('second', 'zeroth');
\&    $len = $t->Length;     # number of key-value pairs
.Ve
.Vb 3
\&    $t->Reorder(reverse @keys);
\&    $t->SortByKey;
\&    $t->SortByValue;
.Ve
.SH "BUGS"
.IX Header "BUGS"
You cannot specify a negative length to \f(CW\*(C`Splice\*(C'\fR. Negative indexes are \s-1OK\s0,
though.
.PP
Indexing always begins at 0 (despite the current \f(CW\*(C`$[\*(C'\fR setting) for 
all the functions.
.SH "TODO"
.IX Header "TODO"
Addition of elements with keys that already exist to the end of the IxHash
must be controlled by a switch.
.PP
Provide \f(CW\*(C`TIEARRAY\*(C'\fR interface when it stabilizes in Perl.
.PP
Rewrite using XSUBs for efficiency.
.SH "AUTHOR"
.IX Header "AUTHOR"
Gurusamy Sarathy        gsar@umich.edu
.PP
Copyright (c) 1995 Gurusamy Sarathy. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.SH "VERSION"
.IX Header "VERSION"
Version 1.21    20 Nov 1997
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fIperl\fR\|(1)