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
  
/*\ 
||| This file a part of Pike, and is copyright by Fredrik Hubinette 
||| Pike is distributed as GPL (General Public License) 
||| See the files COPYING and DISCLAIMER for more information. 
\*/ 
 
/* 
 * $Id: array.h,v 1.18 1999/10/03 21:44:18 hubbe Exp $ 
 */ 
#ifndef ARRAY_H 
#define ARRAY_H 
 
#include "las.h" 
 
struct array 
{ 
  INT32 refs;               /* Reference count */ 
#ifdef PIKE_SECURITY 
  struct object *prot; 
#endif 
  struct array *next;     /* we need to keep track of all arrays */ 
  struct array *prev;       /* Another pointer, so we don't have to search 
                         * when freeing arrays */ 
  INT32 size;               /* number of items in this array */ 
  INT32 malloced_size;      /* number of elements that can fit in this array */ 
  TYPE_FIELD type_field;/* A bitfield with one bit for each type. 
                         * Bits can be set that don't exist in the array 
                         * though. 
                         */ 
  INT16 flags;          /* ARRAY_* flags */ 
  struct svalue item[1]; 
}; 
 
#define ARRAY_WEAK_FLAG 1 
#define ARRAY_CYCLIC 2 
#define ARRAY_LVALUE 4 
#define ARRAY_WEAK_SHRINK 8 
 
extern struct array empty_array; 
 
#if defined(DEBUG_MALLOC) && defined(PIKE_DEBUG) 
#define ITEM(X) (((struct array *)(debug_malloc_pass((X))))->item) 
#else 
#define ITEM(X) ((X)->item) 
#endif 
 
/* These are arguments for the function 'merge' which merges two sorted 
 * set stored in arrays in the way you specify 
 */ 
#define PIKE_ARRAY_OP_A 1 
#define PIKE_ARRAY_OP_SKIP_A 2 
#define PIKE_ARRAY_OP_TAKE_A 3 
#define PIKE_ARRAY_OP_B 4 
#define PIKE_ARRAY_OP_SKIP_B 8 
#define PIKE_ARRAY_OP_TAKE_B 12 
#define PIKE_MINTERM(X,Y,Z) (((X)<<8)+((Y)<<4)+(Z)) 
 
#define PIKE_ARRAY_OP_AND PIKE_MINTERM(PIKE_ARRAY_OP_SKIP_A,PIKE_ARRAY_OP_SKIP_A | PIKE_ARRAY_OP_TAKE_B,PIKE_ARRAY_OP_SKIP_B) 
#define PIKE_ARRAY_OP_AND_LEFT PIKE_MINTERM(PIKE_ARRAY_OP_SKIP_A,PIKE_ARRAY_OP_SKIP_B | PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_B) 
#define PIKE_ARRAY_OP_OR  PIKE_MINTERM(PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_A | PIKE_ARRAY_OP_TAKE_B,PIKE_ARRAY_OP_TAKE_B) 
#define PIKE_ARRAY_OP_OR_LEFT  PIKE_MINTERM(PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_B | PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_TAKE_B) 
#define PIKE_ARRAY_OP_XOR PIKE_MINTERM(PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_A | PIKE_ARRAY_OP_SKIP_B,PIKE_ARRAY_OP_TAKE_B) 
#define PIKE_ARRAY_OP_ADD PIKE_MINTERM(PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_TAKE_A | PIKE_ARRAY_OP_TAKE_B ,PIKE_ARRAY_OP_TAKE_B) 
#define PIKE_ARRAY_OP_SUB PIKE_MINTERM(PIKE_ARRAY_OP_TAKE_A,PIKE_ARRAY_OP_SKIP_A ,PIKE_ARRAY_OP_SKIP_B) 
 
 
#define free_array(V) do{ struct array *v_=(V); debug_malloc_touch(v_); if(!--v_->refs) really_free_array(v_); }while(0) 
 
#define allocate_array(X) low_allocate_array((X),0) 
#define allocate_array_no_init(X,Y) low_allocate_array((X),(Y)) 
 
typedef int (*cmpfun)(struct svalue *,struct svalue *); 
typedef int (*short_cmpfun)(union anything *, union anything *); 
typedef short_cmpfun (*cmpfun_getter)(TYPE_T); 
 
 
/* Prototypes begin here */ 
struct array *low_allocate_array(INT32 size,INT32 extra_space); 
void really_free_array(struct array *v); 
void do_free_array(struct array *a); 
void array_index_no_free(struct svalue *s,struct array *v,INT32 index); 
void array_index(struct svalue *s,struct array *v,INT32 index); 
void simple_array_index_no_free(struct svalue *s, 
                                struct array *a,struct svalue *ind); 
void array_free_index(struct array *v,INT32 index); 
void array_set_index(struct array *v,INT32 index, struct svalue *s); 
void simple_set_index(struct array *a,struct svalue *ind,struct svalue *s); 
struct array *array_insert(struct array *v,struct svalue *s,INT32 index); 
struct array *resize_array(struct array *a, INT32 size); 
struct array *array_shrink(struct array *v,INT32 size); 
struct array *array_remove(struct array *v,INT32 index); 
INT32 array_search(struct array *v, struct svalue *s,INT32 start); 
struct array *slice_array(struct array *v,INT32 start,INT32 end); 
struct array *friendly_slice_array(struct array *v,INT32 start,INT32 end); 
struct array *copy_array(struct array *v); 
void check_array_for_destruct(struct array *v); 
INT32 array_find_destructed_object(struct array *v); 
INT32 *get_order(struct array *v, cmpfun fun); 
void sort_array_destructively(struct array *v); 
INT32 *get_set_order(struct array *a); 
INT32 *get_switch_order(struct array *a); 
INT32 *get_alpha_order(struct array *a); 
INT32 set_lookup(struct array *a, struct svalue *s); 
INT32 switch_lookup(struct array *a, struct svalue *s); 
struct array *order_array(struct array *v, INT32 *order); 
struct array *reorder_and_copy_array(struct array *v, INT32 *order); 
void array_fix_type_field(struct array *v); 
void array_check_type_field(struct array *v); 
struct array *compact_array(struct array *v); 
union anything *low_array_get_item_ptr(struct array *a, 
                                       INT32 ind, 
                                       TYPE_T t); 
union anything *array_get_item_ptr(struct array *a, 
                                   struct svalue *ind, 
                                   TYPE_T t); 
INT32 * merge(struct array *a,struct array *b,INT32 opcode); 
struct array *array_zip(struct array *a, struct array *b,INT32 *zipper); 
struct array *add_arrays(struct svalue *argp, INT32 args); 
int array_equal_p(struct array *a, struct array *b, struct processing *p); 
struct array *merge_array_with_order(struct array *a, struct array *b,INT32 op); 
struct array *merge_array_without_order2(struct array *a, struct array *b,INT32 op); 
struct array *merge_array_without_order(struct array *a, 
                                        struct array *b, 
                                        INT32 op); 
struct array *subtract_arrays(struct array *a, struct array *b); 
struct array *and_arrays(struct array *a, struct array *b); 
int check_that_array_is_constant(struct array *a); 
node *make_node_from_array(struct array *a); 
void push_array_items(struct array *a); 
void describe_array_low(struct array *a, struct processing *p, int indent); 
void simple_describe_array(struct array *a); 
void describe_index(struct array *a, 
                    int e, 
                    struct processing *p, 
                    int indent); 
void describe_array(struct array *a,struct processing *p,int indent); 
struct array *aggregate_array(INT32 args); 
struct array *append_array(struct array *a, struct svalue *s); 
struct array *explode(struct pike_string *str, 
                       struct pike_string *del); 
struct pike_string *implode(struct array *a,struct pike_string *del); 
struct array *copy_array_recursively(struct array *a,struct processing *p); 
void apply_array(struct array *a, INT32 args); 
struct array *reverse_array(struct array *a); 
void array_replace(struct array *a, 
                   struct svalue *from, 
                   struct svalue *to); 
void check_array(struct array *a); 
void check_all_arrays(void); 
void gc_mark_array_as_referenced(struct array *a); 
void gc_check_all_arrays(void); 
void gc_mark_all_arrays(void); 
void gc_free_all_unreferenced_arrays(void); 
void debug_dump_type_field(TYPE_FIELD t); 
void debug_dump_array(struct array *a); 
void zap_all_arrays(void); 
void count_memory_in_arrays(INT32 *num_, INT32 *size_); 
struct array *explode_array(struct array *a, struct array *b); 
struct array *implode_array(struct array *a, struct array *b); 
/* Prototypes end here */ 
 
 
#endif