Mercurial > hg > xemacs-beta
annotate src/rangetab.c @ 5168:cf900a2f1fa3
extract gap array from extents.c, use in range tables
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-03-22 Ben Wing <ben@xemacs.org>
* Makefile.in.in (objs):
* array.c:
* array.c (gap_array_adjust_markers):
* array.c (gap_array_move_gap):
* array.c (gap_array_make_gap):
* array.c (gap_array_insert_els):
* array.c (gap_array_delete_els):
* array.c (gap_array_make_marker):
* array.c (gap_array_delete_marker):
* array.c (gap_array_delete_all_markers):
* array.c (gap_array_clone):
* array.h:
* depend:
* emacs.c (main_1):
* extents.c:
* extents.c (EXTENT_GAP_ARRAY_AT):
* extents.c (extent_list_num_els):
* extents.c (extent_list_locate):
* extents.c (extent_list_at):
* extents.c (extent_list_delete_all):
* extents.c (allocate_extent_list):
* extents.c (syms_of_extents):
* extents.h:
* extents.h (XEXTENT_LIST_MARKER):
* lisp.h:
* rangetab.c:
* rangetab.c (mark_range_table):
* rangetab.c (print_range_table):
* rangetab.c (range_table_equal):
* rangetab.c (range_table_hash):
* rangetab.c (verify_range_table):
* rangetab.c (get_range_table_pos):
* rangetab.c (Fmake_range_table):
* rangetab.c (Fcopy_range_table):
* rangetab.c (Fget_range_table):
* rangetab.c (put_range_table):
* rangetab.c (Fclear_range_table):
* rangetab.c (Fmap_range_table):
* rangetab.c (unified_range_table_bytes_needed):
* rangetab.c (unified_range_table_copy_data):
* rangetab.c (unified_range_table_lookup):
* rangetab.h:
* rangetab.h (struct range_table_entry):
* rangetab.h (struct Lisp_Range_Table):
* rangetab.h (rangetab_gap_array_at):
* symsinit.h:
Rename dynarr.c to array.c. Move gap array from extents.c to array.c.
Extract dynarr, gap array and stack-like malloc into new file array.h.
Rename GAP_ARRAY_NUM_ELS -> gap_array_length(). Add gap_array_at(),
gap_array_atp().
Rewrite range table code to use gap arrays. Make put_range_table()
smarter so that its operation is O(log n) for adding a localized
range.
* gc.c (lispdesc_block_size_1):
Don't ABORT() when two elements are located at the same place.
This will happen with a size-0 gap array -- both parts of the array
(before and after gap) are in the same place.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Mon, 22 Mar 2010 19:12:15 -0500 |
parents | 88bd4f3ef8e4 |
children | 6c6d78781d59 |
rev | line source |
---|---|
428 | 1 /* XEmacs routines to deal with range tables. |
2 Copyright (C) 1995 Sun Microsystems, Inc. | |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
3 Copyright (C) 1995, 2002, 2004, 2005, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
24 /* Written by Ben Wing, August 1995. */ | |
25 | |
26 #include <config.h> | |
27 #include "lisp.h" | |
28 #include "rangetab.h" | |
29 | |
30 Lisp_Object Qrange_tablep; | |
31 Lisp_Object Qrange_table; | |
32 | |
2421 | 33 Lisp_Object Qstart_closed_end_open; |
34 Lisp_Object Qstart_open_end_open; | |
35 Lisp_Object Qstart_closed_end_closed; | |
36 Lisp_Object Qstart_open_end_closed; | |
37 | |
428 | 38 |
39 /************************************************************************/ | |
40 /* Range table object */ | |
41 /************************************************************************/ | |
42 | |
2421 | 43 static enum range_table_type |
44 range_table_symbol_to_type (Lisp_Object symbol) | |
45 { | |
46 if (NILP (symbol)) | |
47 return RANGE_START_CLOSED_END_OPEN; | |
48 | |
49 CHECK_SYMBOL (symbol); | |
50 if (EQ (symbol, Qstart_closed_end_open)) | |
51 return RANGE_START_CLOSED_END_OPEN; | |
52 if (EQ (symbol, Qstart_closed_end_closed)) | |
53 return RANGE_START_CLOSED_END_CLOSED; | |
54 if (EQ (symbol, Qstart_open_end_open)) | |
55 return RANGE_START_OPEN_END_OPEN; | |
56 if (EQ (symbol, Qstart_open_end_closed)) | |
57 return RANGE_START_OPEN_END_CLOSED; | |
58 | |
59 invalid_constant ("Unknown range table type", symbol); | |
60 RETURN_NOT_REACHED (RANGE_START_CLOSED_END_OPEN); | |
61 } | |
62 | |
63 static Lisp_Object | |
64 range_table_type_to_symbol (enum range_table_type type) | |
65 { | |
66 switch (type) | |
67 { | |
68 case RANGE_START_CLOSED_END_OPEN: | |
69 return Qstart_closed_end_open; | |
70 case RANGE_START_CLOSED_END_CLOSED: | |
71 return Qstart_closed_end_closed; | |
72 case RANGE_START_OPEN_END_OPEN: | |
73 return Qstart_open_end_open; | |
74 case RANGE_START_OPEN_END_CLOSED: | |
75 return Qstart_open_end_closed; | |
76 } | |
77 | |
2500 | 78 ABORT (); |
2421 | 79 return Qnil; |
80 } | |
81 | |
428 | 82 /* We use a sorted array of ranges. |
83 | |
84 #### We should be using the gap array stuff from extents.c. This | |
85 is not hard but just requires moving that stuff out of that file. */ | |
86 | |
87 static Lisp_Object | |
88 mark_range_table (Lisp_Object obj) | |
89 { | |
440 | 90 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
428 | 91 int i; |
92 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
93 for (i = 0; i < gap_array_length (rt->entries); i++) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
94 mark_object (rangetab_gap_array_at (rt->entries, i).val); |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4391
diff
changeset
|
95 |
428 | 96 return Qnil; |
97 } | |
98 | |
99 static void | |
2286 | 100 print_range_table (Lisp_Object obj, Lisp_Object printcharfun, |
101 int UNUSED (escapeflag)) | |
428 | 102 { |
440 | 103 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
428 | 104 int i; |
105 | |
2421 | 106 if (print_readably) |
107 write_fmt_string_lisp (printcharfun, "#s(range-table type %s data (", | |
108 1, range_table_type_to_symbol (rt->type)); | |
109 else | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4831
diff
changeset
|
110 write_ascstring (printcharfun, "#<range-table "); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
111 for (i = 0; i < gap_array_length (rt->entries); i++) |
428 | 112 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
113 struct range_table_entry rte = rangetab_gap_array_at (rt->entries, i); |
2421 | 114 int so, ec; |
428 | 115 if (i > 0) |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4831
diff
changeset
|
116 write_ascstring (printcharfun, " "); |
2421 | 117 switch (rt->type) |
118 { | |
119 case RANGE_START_CLOSED_END_OPEN: so = 0, ec = 0; break; | |
120 case RANGE_START_CLOSED_END_CLOSED: so = 0, ec = 1; break; | |
121 case RANGE_START_OPEN_END_OPEN: so = 1, ec = 0; break; | |
122 case RANGE_START_OPEN_END_CLOSED: so = 1; ec = 1; break; | |
2500 | 123 default: ABORT (); so = 0, ec = 0; break; |
2421 | 124 } |
125 write_fmt_string (printcharfun, "%c%ld %ld%c ", | |
126 print_readably ? '(' : so ? '(' : '[', | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
127 (long) (rte.first - so), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
128 (long) (rte.last - ec), |
2421 | 129 print_readably ? ')' : ec ? ']' : ')' |
130 ); | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
131 print_internal (rte.val, printcharfun, 1); |
428 | 132 } |
2421 | 133 if (print_readably) |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4831
diff
changeset
|
134 write_ascstring (printcharfun, "))"); |
2421 | 135 else |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
136 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj)); |
428 | 137 } |
138 | |
139 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4831
diff
changeset
|
140 range_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) |
428 | 141 { |
440 | 142 Lisp_Range_Table *rt1 = XRANGE_TABLE (obj1); |
143 Lisp_Range_Table *rt2 = XRANGE_TABLE (obj2); | |
428 | 144 int i; |
145 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
146 if (gap_array_length (rt1->entries) != gap_array_length (rt2->entries)) |
428 | 147 return 0; |
148 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
149 for (i = 0; i < gap_array_length (rt1->entries); i++) |
428 | 150 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
151 struct range_table_entry *rte1 = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
152 rangetab_gap_array_atp (rt1->entries, i); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
153 struct range_table_entry *rte2 = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
154 rangetab_gap_array_atp (rt2->entries, i); |
428 | 155 |
156 if (rte1->first != rte2->first | |
157 || rte1->last != rte2->last | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4831
diff
changeset
|
158 || !internal_equal_0 (rte1->val, rte2->val, depth + 1, foldcase)) |
428 | 159 return 0; |
160 } | |
161 | |
162 return 1; | |
163 } | |
164 | |
2515 | 165 static Hashcode |
428 | 166 range_table_entry_hash (struct range_table_entry *rte, int depth) |
167 { | |
168 return HASH3 (rte->first, rte->last, internal_hash (rte->val, depth + 1)); | |
169 } | |
170 | |
2515 | 171 static Hashcode |
428 | 172 range_table_hash (Lisp_Object obj, int depth) |
173 { | |
440 | 174 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
428 | 175 int i; |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
176 int size = gap_array_length (rt->entries); |
2515 | 177 Hashcode hash = size; |
428 | 178 |
179 /* approach based on internal_array_hash(). */ | |
180 if (size <= 5) | |
181 { | |
182 for (i = 0; i < size; i++) | |
183 hash = HASH2 (hash, | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
184 range_table_entry_hash |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
185 (rangetab_gap_array_atp (rt->entries, i), depth)); |
428 | 186 return hash; |
187 } | |
188 | |
189 /* just pick five elements scattered throughout the array. | |
190 A slightly better approach would be to offset by some | |
191 noise factor from the points chosen below. */ | |
192 for (i = 0; i < 5; i++) | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
193 hash = HASH2 (hash, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
194 range_table_entry_hash |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
195 (rangetab_gap_array_atp (rt->entries, i*size/5), depth)); |
428 | 196 return hash; |
197 } | |
198 | |
1204 | 199 static const struct memory_description rte_description_1[] = { |
440 | 200 { XD_LISP_OBJECT, offsetof (range_table_entry, val) }, |
428 | 201 { XD_END } |
202 }; | |
203 | |
1204 | 204 static const struct sized_memory_description rte_description = { |
440 | 205 sizeof (range_table_entry), |
428 | 206 rte_description_1 |
207 }; | |
208 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
209 static const struct memory_description rtega_description_1[] = { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
210 XD_GAP_ARRAY_DESC (&rte_description), |
428 | 211 { XD_END } |
212 }; | |
213 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
214 static const struct sized_memory_description rtega_description = { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
215 0, rtega_description_1 |
428 | 216 }; |
217 | |
1204 | 218 static const struct memory_description range_table_description[] = { |
2551 | 219 { XD_BLOCK_PTR, offsetof (Lisp_Range_Table, entries), 1, |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
220 { &rtega_description } }, |
428 | 221 { XD_END } |
222 }; | |
223 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
224 DEFINE_DUMPABLE_LISP_OBJECT ("range-table", range_table, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
225 mark_range_table, print_range_table, 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
226 range_table_equal, range_table_hash, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
227 range_table_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
228 Lisp_Range_Table); |
428 | 229 |
230 /************************************************************************/ | |
231 /* Range table operations */ | |
232 /************************************************************************/ | |
233 | |
800 | 234 #ifdef ERROR_CHECK_STRUCTURES |
428 | 235 |
236 static void | |
440 | 237 verify_range_table (Lisp_Range_Table *rt) |
428 | 238 { |
239 int i; | |
240 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
241 for (i = 0; i < gap_array_length (rt->entries); i++) |
428 | 242 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
243 struct range_table_entry *rte = rangetab_gap_array_atp (rt->entries, i); |
428 | 244 assert (rte->last >= rte->first); |
245 if (i > 0) | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
246 assert (rangetab_gap_array_at (rt->entries, i - 1).last <= rte->first); |
428 | 247 } |
248 } | |
249 | |
250 #else | |
251 | |
252 #define verify_range_table(rt) | |
253 | |
254 #endif | |
255 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
256 /* Locate the range table entry corresponding to the value POS, and return |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
257 it. If found, FOUNDP is set to 1 and the return value specifies an entry |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
258 that encloses POS. Otherwise, FOUNDP is set to 0 and the return value |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
259 specifies where an entry that encloses POS would be inserted. */ |
428 | 260 |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
261 static Elemcount |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
262 get_range_table_pos (Elemcount pos, Elemcount nentries, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
263 struct range_table_entry *tab, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
264 Elemcount gappos, Elemcount gapsize, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
265 int *foundp) |
428 | 266 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
267 Elemcount left = 0, right = nentries; |
428 | 268 |
269 /* binary search for the entry. Based on similar code in | |
270 extent_list_locate(). */ | |
271 while (left != right) | |
272 { | |
273 /* RIGHT might not point to a valid entry (i.e. it's at the end | |
274 of the list), so NEWPOS must round down. */ | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
275 Elemcount newpos = (left + right) >> 1; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
276 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
277 tab + GAP_ARRAY_ARRAY_TO_MEMORY_POS_1 (newpos, gappos, gapsize); |
2421 | 278 if (pos >= entry->last) |
279 left = newpos + 1; | |
428 | 280 else if (pos < entry->first) |
281 right = newpos; | |
282 else | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
283 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
284 *foundp = 1; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
285 return newpos; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
286 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
287 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
288 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
289 *foundp = 0; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
290 return left; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
291 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
292 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
293 /* Look up in a range table without the gap array wrapper. |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
294 Used also by the unified range table format. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
295 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
296 static Lisp_Object |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
297 get_range_table (Elemcount pos, Elemcount nentries, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
298 struct range_table_entry *tab, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
299 Elemcount gappos, Elemcount gapsize, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
300 Lisp_Object default_) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
301 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
302 int foundp; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
303 Elemcount entrypos = get_range_table_pos (pos, nentries, tab, gappos, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
304 gapsize, &foundp); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
305 if (foundp) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
306 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
307 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
308 tab + GAP_ARRAY_ARRAY_TO_MEMORY_POS_1 (entrypos, gappos, gapsize); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
309 return entry->val; |
428 | 310 } |
311 | |
312 return default_; | |
313 } | |
314 | |
315 DEFUN ("range-table-p", Frange_table_p, 1, 1, 0, /* | |
316 Return non-nil if OBJECT is a range table. | |
317 */ | |
318 (object)) | |
319 { | |
320 return RANGE_TABLEP (object) ? Qt : Qnil; | |
321 } | |
322 | |
2421 | 323 DEFUN ("range-table-type", Frange_table_type, 1, 1, 0, /* |
4713
312503644bc3
Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4690
diff
changeset
|
324 Return the type of RANGE-TABLE. |
312503644bc3
Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4690
diff
changeset
|
325 |
312503644bc3
Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4690
diff
changeset
|
326 This will be a symbol describing how ranges in RANGE-TABLE function at their |
312503644bc3
Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4690
diff
changeset
|
327 ends; see `make-range-table'. |
2421 | 328 */ |
329 (range_table)) | |
330 { | |
331 CHECK_RANGE_TABLE (range_table); | |
332 return range_table_type_to_symbol (XRANGE_TABLE (range_table)->type); | |
333 } | |
334 | |
335 DEFUN ("make-range-table", Fmake_range_table, 0, 1, 0, /* | |
428 | 336 Return a new, empty range table. |
337 You can manipulate it using `put-range-table', `get-range-table', | |
338 `remove-range-table', and `clear-range-table'. | |
2421 | 339 Range tables allow you to efficiently set values for ranges of integers. |
340 | |
341 TYPE is a symbol indicating how ranges are assumed to function at their | |
342 ends. It can be one of | |
343 | |
344 SYMBOL RANGE-START RANGE-END | |
345 ------ ----------- --------- | |
346 `start-closed-end-open' (the default) closed open | |
347 `start-closed-end-closed' closed closed | |
348 `start-open-end-open' open open | |
349 `start-open-end-closed' open closed | |
350 | |
351 A `closed' endpoint of a range means that the number at that end is included | |
352 in the range. For an `open' endpoint, the number would not be included. | |
353 | |
354 For example, a closed-open range from 5 to 20 would be indicated as [5, | |
355 20) where a bracket indicates a closed end and a parenthesis an open end, | |
356 and would mean `all the numbers between 5 and 20', including 5 but not 20. | |
357 This seems a little strange at first but is in fact extremely common in | |
358 the outside world as well as in computers and makes things work sensibly. | |
359 For example, if I say "there are seven days between today and next week | |
360 today", I'm including today but not next week today; if I included both, | |
361 there would be eight days. Similarly, there are 15 (= 20 - 5) elements in | |
362 the range [5, 20), but 16 in the range [5, 20]. | |
428 | 363 */ |
2421 | 364 (type)) |
428 | 365 { |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
366 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (range_table); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
367 Lisp_Range_Table *rt = XRANGE_TABLE (obj); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
368 rt->entries = make_gap_array (sizeof (struct range_table_entry), 0); |
2421 | 369 rt->type = range_table_symbol_to_type (type); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
370 return obj; |
428 | 371 } |
372 | |
373 DEFUN ("copy-range-table", Fcopy_range_table, 1, 1, 0, /* | |
444 | 374 Return a new range table which is a copy of RANGE-TABLE. |
375 It will contain the same values for the same ranges as RANGE-TABLE. | |
376 The values will not themselves be copied. | |
428 | 377 */ |
444 | 378 (range_table)) |
428 | 379 { |
440 | 380 Lisp_Range_Table *rt, *rtnew; |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
381 Lisp_Object obj; |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
382 Elemcount i; |
428 | 383 |
444 | 384 CHECK_RANGE_TABLE (range_table); |
385 rt = XRANGE_TABLE (range_table); | |
428 | 386 |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
387 obj = ALLOC_NORMAL_LISP_OBJECT (range_table); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
388 rtnew = XRANGE_TABLE (obj); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
389 rtnew->entries = make_gap_array (sizeof (struct range_table_entry), 0); |
2421 | 390 rtnew->type = rt->type; |
428 | 391 |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
392 for (i = 0; i < gap_array_length (rt->entries); i++) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
393 rtnew->entries = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
394 gap_array_insert_els (rtnew->entries, i, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
395 rangetab_gap_array_atp (rt->entries, i), 1); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
396 return obj; |
428 | 397 } |
398 | |
399 DEFUN ("get-range-table", Fget_range_table, 2, 3, 0, /* | |
444 | 400 Find value for position POS in RANGE-TABLE. |
428 | 401 If there is no corresponding value, return DEFAULT (defaults to nil). |
402 */ | |
444 | 403 (pos, range_table, default_)) |
428 | 404 { |
440 | 405 Lisp_Range_Table *rt; |
428 | 406 |
444 | 407 CHECK_RANGE_TABLE (range_table); |
408 rt = XRANGE_TABLE (range_table); | |
428 | 409 |
410 CHECK_INT_COERCE_CHAR (pos); | |
411 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
412 return get_range_table (XINT (pos), gap_array_length (rt->entries), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
413 gap_array_begin (rt->entries, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
414 struct range_table_entry), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
415 gap_array_gappos (rt->entries), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
416 gap_array_gapsize (rt->entries), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
417 default_); |
428 | 418 } |
419 | |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
420 static void |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
421 external_to_internal_adjust_ends (enum range_table_type type, |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
422 EMACS_INT *first, EMACS_INT *last) |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
423 { |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
424 /* Fix up the numbers in accordance with the open/closedness to make |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
425 them behave like default open/closed. */ |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
426 switch (type) |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
427 { |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
428 case RANGE_START_CLOSED_END_OPEN: break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
429 case RANGE_START_CLOSED_END_CLOSED: (*last)++; break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
430 case RANGE_START_OPEN_END_OPEN: (*first)++; break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
431 case RANGE_START_OPEN_END_CLOSED: (*first)++, (*last)++; break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
432 } |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
433 } |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
434 |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
435 static void |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
436 internal_to_external_adjust_ends (enum range_table_type type, |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
437 EMACS_INT *first, EMACS_INT *last) |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
438 { |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
439 /* Reverse the changes made in external_to_internal_adjust_ends(). |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
440 */ |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
441 switch (type) |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
442 { |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
443 case RANGE_START_CLOSED_END_OPEN: break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
444 case RANGE_START_CLOSED_END_CLOSED: (*last)--; break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
445 case RANGE_START_OPEN_END_OPEN: (*first)--; break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
446 case RANGE_START_OPEN_END_CLOSED: (*first)--, (*last)--; break; |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
447 } |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
448 } |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
449 |
428 | 450 void |
451 put_range_table (Lisp_Object table, EMACS_INT first, | |
452 EMACS_INT last, Lisp_Object val) | |
453 { | |
454 int i; | |
455 int insert_me_here = -1; | |
440 | 456 Lisp_Range_Table *rt = XRANGE_TABLE (table); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
457 int foundp; |
428 | 458 |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
459 external_to_internal_adjust_ends (rt->type, &first, &last); |
2421 | 460 if (first == last) |
461 return; | |
462 if (first > last) | |
463 /* This will happen if originally first == last and both ends are | |
464 open. #### Should we signal an error? */ | |
465 return; | |
466 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
467 if (DUMPEDP (rt->entries)) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
468 rt->entries = gap_array_clone (rt->entries); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
469 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
470 i = get_range_table_pos (first, gap_array_length (rt->entries), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
471 gap_array_begin (rt->entries, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
472 struct range_table_entry), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
473 gap_array_gappos (rt->entries), |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
474 gap_array_gapsize (rt->entries), &foundp); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
475 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
476 #ifdef ERROR_CHECK_TYPES |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
477 if (foundp) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
478 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
479 if (i < gap_array_length (rt->entries)) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
480 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
481 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
482 rangetab_gap_array_atp (rt->entries, i); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
483 assert (first >= entry->first && first < entry->last); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
484 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
485 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
486 else |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
487 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
488 if (i < gap_array_length (rt->entries)) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
489 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
490 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
491 rangetab_gap_array_atp (rt->entries, i); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
492 assert (first < entry->first); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
493 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
494 if (i > 0) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
495 { |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
496 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
497 rangetab_gap_array_atp (rt->entries, i - 1); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
498 assert (first >= entry->last); |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
499 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
500 } |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
501 #endif /* ERROR_CHECK_TYPES */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
502 |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
503 /* If the beginning of the new range isn't within any existing range, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
504 it might still be just grazing the end of an end-open range (remember, |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
505 internally all ranges are start-close end-open); so back up one |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
506 so we consider this range. */ |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
507 if (!foundp && i > 0) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
508 i--; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
509 |
428 | 510 /* Now insert in the proper place. This gets tricky because |
511 we may be overlapping one or more existing ranges and need | |
512 to fix them up. */ | |
513 | |
514 /* First delete all sections of any existing ranges that overlap | |
515 the new range. */ | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
516 for (; i < gap_array_length (rt->entries); i++) |
428 | 517 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
518 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
519 rangetab_gap_array_atp (rt->entries, i); |
428 | 520 /* We insert before the first range that begins at or after the |
521 new range. */ | |
522 if (entry->first >= first && insert_me_here < 0) | |
523 insert_me_here = i; | |
524 if (entry->last < first) | |
525 /* completely before the new range. */ | |
526 continue; | |
527 if (entry->first > last) | |
528 /* completely after the new range. No more possibilities of | |
529 finding overlapping ranges. */ | |
530 break; | |
2421 | 531 /* At this point the existing ENTRY overlaps or touches the new one. */ |
428 | 532 if (entry->first < first && entry->last <= last) |
533 { | |
534 /* looks like: | |
535 | |
2421 | 536 [ NEW ) |
537 [ EXISTING ) | |
538 | |
539 or | |
540 | |
541 [ NEW ) | |
542 [ EXISTING ) | |
428 | 543 |
544 */ | |
545 /* truncate the end off of it. */ | |
2421 | 546 entry->last = first; |
428 | 547 } |
548 else if (entry->first < first && entry->last > last) | |
549 /* looks like: | |
550 | |
2421 | 551 [ NEW ) |
552 [ EXISTING ) | |
428 | 553 |
554 */ | |
555 /* need to split this one in two. */ | |
556 { | |
557 struct range_table_entry insert_me_too; | |
558 | |
2421 | 559 insert_me_too.first = last; |
428 | 560 insert_me_too.last = entry->last; |
561 insert_me_too.val = entry->val; | |
2421 | 562 entry->last = first; |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
563 rt->entries = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
564 gap_array_insert_els (rt->entries, i + 1, &insert_me_too, 1); |
428 | 565 } |
2421 | 566 else if (entry->last >= last) |
428 | 567 { |
568 /* looks like: | |
569 | |
2421 | 570 [ NEW ) |
571 [ EXISTING ) | |
572 | |
573 or | |
574 | |
575 [ NEW ) | |
576 [ EXISTING ) | |
428 | 577 |
578 */ | |
579 /* truncate the start off of it. */ | |
2421 | 580 entry->first = last; |
428 | 581 } |
582 else | |
583 { | |
584 /* existing is entirely within new. */ | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
585 gap_array_delete_els (rt->entries, i, 1); |
428 | 586 i--; /* back up since everything shifted one to the left. */ |
587 } | |
588 } | |
589 | |
590 /* Someone asked us to delete the range, not insert it. */ | |
591 if (UNBOUNDP (val)) | |
592 return; | |
593 | |
594 /* Now insert the new entry, maybe at the end. */ | |
595 | |
596 if (insert_me_here < 0) | |
597 insert_me_here = i; | |
598 | |
599 { | |
600 struct range_table_entry insert_me; | |
601 | |
602 insert_me.first = first; | |
603 insert_me.last = last; | |
604 insert_me.val = val; | |
605 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
606 rt->entries = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
607 gap_array_insert_els (rt->entries, insert_me_here, &insert_me, 1); |
428 | 608 } |
609 | |
610 /* Now see if we can combine this entry with adjacent ones just | |
611 before or after. */ | |
612 | |
613 if (insert_me_here > 0) | |
614 { | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
615 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
616 rangetab_gap_array_atp (rt->entries, insert_me_here - 1); |
2421 | 617 if (EQ (val, entry->val) && entry->last == first) |
428 | 618 { |
619 entry->last = last; | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
620 gap_array_delete_els (rt->entries, insert_me_here, 1); |
428 | 621 insert_me_here--; |
622 /* We have morphed into a larger range. Update our records | |
623 in case we also combine with the one after. */ | |
624 first = entry->first; | |
625 } | |
626 } | |
627 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
628 if (insert_me_here < gap_array_length (rt->entries) - 1) |
428 | 629 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
630 struct range_table_entry *entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
631 rangetab_gap_array_atp (rt->entries, insert_me_here + 1); |
2421 | 632 if (EQ (val, entry->val) && entry->first == last) |
428 | 633 { |
634 entry->first = first; | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
635 gap_array_delete_els (rt->entries, insert_me_here, 1); |
428 | 636 } |
637 } | |
638 } | |
639 | |
640 DEFUN ("put-range-table", Fput_range_table, 4, 4, 0, /* | |
2421 | 641 Set the value for range START .. END to be VALUE in RANGE-TABLE. |
428 | 642 */ |
444 | 643 (start, end, value, range_table)) |
428 | 644 { |
645 EMACS_INT first, last; | |
646 | |
444 | 647 CHECK_RANGE_TABLE (range_table); |
428 | 648 CHECK_INT_COERCE_CHAR (start); |
649 first = XINT (start); | |
650 CHECK_INT_COERCE_CHAR (end); | |
651 last = XINT (end); | |
652 if (first > last) | |
563 | 653 invalid_argument_2 ("start must be <= end", start, end); |
428 | 654 |
444 | 655 put_range_table (range_table, first, last, value); |
656 verify_range_table (XRANGE_TABLE (range_table)); | |
428 | 657 return Qnil; |
658 } | |
659 | |
660 DEFUN ("remove-range-table", Fremove_range_table, 3, 3, 0, /* | |
2421 | 661 Remove the value for range START .. END in RANGE-TABLE. |
428 | 662 */ |
444 | 663 (start, end, range_table)) |
428 | 664 { |
444 | 665 return Fput_range_table (start, end, Qunbound, range_table); |
428 | 666 } |
667 | |
668 DEFUN ("clear-range-table", Fclear_range_table, 1, 1, 0, /* | |
444 | 669 Flush RANGE-TABLE. |
428 | 670 */ |
444 | 671 (range_table)) |
428 | 672 { |
444 | 673 CHECK_RANGE_TABLE (range_table); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
674 gap_array_delete_all_els (XRANGE_TABLE (range_table)->entries); |
428 | 675 return Qnil; |
676 } | |
677 | |
678 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /* | |
444 | 679 Map FUNCTION over entries in RANGE-TABLE, calling it with three args, |
428 | 680 the beginning and end of the range and the corresponding value. |
442 | 681 |
682 Results are guaranteed to be correct (i.e. each entry processed | |
683 exactly once) if FUNCTION modifies or deletes the current entry | |
444 | 684 \(i.e. passes the current range to `put-range-table' or |
4391
cbf129b005df
Clarify #'map-range-table docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3017
diff
changeset
|
685 `remove-range-table'). If FUNCTION modifies or deletes any other entry, |
cbf129b005df
Clarify #'map-range-table docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3017
diff
changeset
|
686 this guarantee doesn't hold. |
428 | 687 */ |
444 | 688 (function, range_table)) |
428 | 689 { |
442 | 690 Lisp_Range_Table *rt; |
691 int i; | |
692 | |
444 | 693 CHECK_RANGE_TABLE (range_table); |
442 | 694 CHECK_FUNCTION (function); |
695 | |
444 | 696 rt = XRANGE_TABLE (range_table); |
442 | 697 |
698 /* Do not "optimize" by pulling out the length computation below! | |
699 FUNCTION may have changed the table. */ | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
700 for (i = 0; i < gap_array_length (rt->entries); i++) |
442 | 701 { |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
702 struct range_table_entry entry = |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
703 rangetab_gap_array_at (rt->entries, i); |
442 | 704 EMACS_INT first, last; |
705 Lisp_Object args[4]; | |
706 int oldlen; | |
707 | |
708 again: | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
709 first = entry.first; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
710 last = entry.last; |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
711 oldlen = gap_array_length (rt->entries); |
442 | 712 args[0] = function; |
2952 | 713 /* Fix up the numbers in accordance with the open/closedness of the |
714 table. */ | |
715 { | |
716 EMACS_INT premier = first, dernier = last; | |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
717 internal_to_external_adjust_ends (rt->type, &premier, &dernier); |
2952 | 718 args[1] = make_int (premier); |
719 args[2] = make_int (dernier); | |
720 } | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
721 args[3] = entry.val; |
442 | 722 Ffuncall (countof (args), args); |
723 /* Has FUNCTION removed the entry? */ | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
724 if (oldlen > gap_array_length (rt->entries) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
725 && i < gap_array_length (rt->entries) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
726 && (first != entry.first || last != entry.last)) |
442 | 727 goto again; |
728 } | |
729 | |
428 | 730 return Qnil; |
731 } | |
732 | |
733 | |
734 /************************************************************************/ | |
735 /* Range table read syntax */ | |
736 /************************************************************************/ | |
737 | |
738 static int | |
2421 | 739 rangetab_type_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
740 Error_Behavior UNUSED (errb)) | |
741 { | |
742 /* #### should deal with ERRB */ | |
743 range_table_symbol_to_type (value); | |
744 return 1; | |
745 } | |
746 | |
747 static int | |
2286 | 748 rangetab_data_validate (Lisp_Object UNUSED (keyword), Lisp_Object value, |
749 Error_Behavior UNUSED (errb)) | |
428 | 750 { |
2367 | 751 /* #### should deal with ERRB */ |
752 EXTERNAL_PROPERTY_LIST_LOOP_3 (range, data, value) | |
428 | 753 { |
754 if (!INTP (range) && !CHARP (range) | |
755 && !(CONSP (range) && CONSP (XCDR (range)) | |
756 && NILP (XCDR (XCDR (range))) | |
757 && (INTP (XCAR (range)) || CHARP (XCAR (range))) | |
758 && (INTP (XCAR (XCDR (range))) || CHARP (XCAR (XCDR (range)))))) | |
563 | 759 sferror ("Invalid range format", range); |
428 | 760 } |
761 | |
762 return 1; | |
763 } | |
764 | |
765 static Lisp_Object | |
2421 | 766 rangetab_instantiate (Lisp_Object plist) |
428 | 767 { |
2425 | 768 Lisp_Object data = Qnil, type = Qnil, rangetab; |
428 | 769 |
2421 | 770 PROPERTY_LIST_LOOP_3 (key, value, plist) |
428 | 771 { |
2421 | 772 if (EQ (key, Qtype)) type = value; |
773 else if (EQ (key, Qdata)) data = value; | |
774 else | |
2500 | 775 ABORT (); |
2421 | 776 } |
777 | |
2425 | 778 rangetab = Fmake_range_table (type); |
428 | 779 |
2421 | 780 { |
781 PROPERTY_LIST_LOOP_3 (range, val, data) | |
782 { | |
783 if (CONSP (range)) | |
784 Fput_range_table (Fcar (range), Fcar (Fcdr (range)), val, | |
785 rangetab); | |
786 else | |
787 Fput_range_table (range, range, val, rangetab); | |
788 } | |
789 } | |
428 | 790 |
791 return rangetab; | |
792 } | |
793 | |
794 | |
795 /************************************************************************/ | |
796 /* Unified range tables */ | |
797 /************************************************************************/ | |
798 | |
799 /* A "unified range table" is a format for storing range tables | |
800 as contiguous blocks of memory. This is used by the regexp | |
801 code, which needs to use range tables to properly handle [] | |
802 constructs in the presence of extended characters but wants to | |
803 store an entire compiled pattern as a contiguous block of memory. | |
804 | |
805 Unified range tables are designed so that they can be placed | |
806 at an arbitrary (possibly mis-aligned) place in memory. | |
807 (Dealing with alignment is a pain in the ass.) | |
808 | |
809 WARNING: No provisions for garbage collection are currently made. | |
810 This means that there must not be any Lisp objects in a unified | |
811 range table that need to be marked for garbage collection. | |
812 Good candidates for objects that can go into a range table are | |
813 | |
814 -- numbers and characters (do not need to be marked) | |
815 -- nil, t (marked elsewhere) | |
816 -- charsets and coding systems (automatically marked because | |
817 they are in a marked list, | |
818 and can't be removed) | |
819 | |
820 Good but slightly less so: | |
821 | |
822 -- symbols (could be uninterned, but that is not likely) | |
823 | |
824 Somewhat less good: | |
825 | |
826 -- buffers, frames, devices (could get deleted) | |
827 | |
828 | |
829 It is expected that you work with range tables in the normal | |
830 format and then convert to unified format when you are done | |
831 making modifications. As such, no functions are provided | |
832 for modifying a unified range table. The only operations | |
833 you can do to unified range tables are | |
834 | |
835 -- look up a value | |
836 -- retrieve all the ranges in an iterative fashion | |
837 | |
838 */ | |
839 | |
840 /* The format of a unified range table is as follows: | |
841 | |
842 -- The first byte contains the number of bytes to skip to find the | |
843 actual start of the table. This deals with alignment constraints, | |
844 since the table might want to go at any arbitrary place in memory. | |
845 -- The next three bytes contain the number of bytes to skip (from the | |
846 *first* byte) to find the stuff after the table. It's stored in | |
847 little-endian format because that's how God intended things. We don't | |
848 necessarily start the stuff at the very end of the table because | |
849 we want to have at least ALIGNOF (EMACS_INT) extra space in case | |
850 we have to move the range table around. (It appears that some | |
851 architectures don't maintain alignment when reallocing.) | |
852 -- At the prescribed offset is a struct unified_range_table, containing | |
853 some number of `struct range_table_entry' entries. */ | |
854 | |
855 struct unified_range_table | |
856 { | |
857 int nentries; | |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
858 enum range_table_type type; |
428 | 859 struct range_table_entry first; |
860 }; | |
861 | |
862 /* Return size in bytes needed to store the data in a range table. */ | |
863 | |
864 int | |
865 unified_range_table_bytes_needed (Lisp_Object rangetab) | |
866 { | |
867 return (sizeof (struct range_table_entry) * | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
868 (gap_array_length (XRANGE_TABLE (rangetab)->entries) - 1) + |
428 | 869 sizeof (struct unified_range_table) + |
870 /* ALIGNOF a struct may be too big. */ | |
871 /* We have four bytes for the size numbers, and an extra | |
872 four or eight bytes for making sure we get the alignment | |
873 OK. */ | |
874 ALIGNOF (EMACS_INT) + 4); | |
875 } | |
876 | |
877 /* Convert a range table into unified format and store in DEST, | |
878 which must be able to hold the number of bytes returned by | |
879 range_table_bytes_needed(). */ | |
880 | |
881 void | |
882 unified_range_table_copy_data (Lisp_Object rangetab, void *dest) | |
883 { | |
884 /* We cast to the above structure rather than just casting to | |
885 char * and adding sizeof(int), because that will lead to | |
886 mis-aligned data on the Alpha machines. */ | |
887 struct unified_range_table *un; | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
888 Gap_Array *rtega = XRANGE_TABLE (rangetab)->entries; |
428 | 889 int total_needed = unified_range_table_bytes_needed (rangetab); |
826 | 890 void *new_dest = ALIGN_PTR ((char *) dest + 4, EMACS_INT); |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
891 Elemcount i; |
428 | 892 |
893 * (char *) dest = (char) ((char *) new_dest - (char *) dest); | |
894 * ((unsigned char *) dest + 1) = total_needed & 0xFF; | |
895 total_needed >>= 8; | |
896 * ((unsigned char *) dest + 2) = total_needed & 0xFF; | |
897 total_needed >>= 8; | |
898 * ((unsigned char *) dest + 3) = total_needed & 0xFF; | |
899 un = (struct unified_range_table *) new_dest; | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
900 un->nentries = gap_array_length (rtega); |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
901 un->type = XRANGE_TABLE (rangetab)->type; |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
902 for (i = 0; i < gap_array_length (rtega); i++) |
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
903 (&un->first)[i] = rangetab_gap_array_at (rtega, i); |
428 | 904 } |
905 | |
906 /* Return number of bytes actually used by a unified range table. */ | |
907 | |
908 int | |
909 unified_range_table_bytes_used (void *unrangetab) | |
910 { | |
911 return ((* ((unsigned char *) unrangetab + 1)) | |
912 + ((* ((unsigned char *) unrangetab + 2)) << 8) | |
913 + ((* ((unsigned char *) unrangetab + 3)) << 16)); | |
914 } | |
915 | |
916 /* Make sure the table is aligned, and move it around if it's not. */ | |
917 static void | |
918 align_the_damn_table (void *unrangetab) | |
919 { | |
920 void *cur_dest = (char *) unrangetab + * (char *) unrangetab; | |
826 | 921 if (cur_dest != ALIGN_PTR (cur_dest, EMACS_INT)) |
428 | 922 { |
923 int count = (unified_range_table_bytes_used (unrangetab) - 4 | |
924 - ALIGNOF (EMACS_INT)); | |
925 /* Find the proper location, just like above. */ | |
826 | 926 void *new_dest = ALIGN_PTR ((char *) unrangetab + 4, EMACS_INT); |
428 | 927 /* memmove() works in the presence of overlapping data. */ |
928 memmove (new_dest, cur_dest, count); | |
929 * (char *) unrangetab = (char) ((char *) new_dest - (char *) unrangetab); | |
930 } | |
931 } | |
932 | |
933 /* Look up a value in a unified range table. */ | |
934 | |
935 Lisp_Object | |
936 unified_range_table_lookup (void *unrangetab, EMACS_INT pos, | |
937 Lisp_Object default_) | |
938 { | |
939 void *new_dest; | |
940 struct unified_range_table *un; | |
941 | |
942 align_the_damn_table (unrangetab); | |
943 new_dest = (char *) unrangetab + * (char *) unrangetab; | |
944 un = (struct unified_range_table *) new_dest; | |
945 | |
5168
cf900a2f1fa3
extract gap array from extents.c, use in range tables
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
946 return get_range_table (pos, un->nentries, &un->first, 0, 0, default_); |
428 | 947 } |
948 | |
949 /* Return number of entries in a unified range table. */ | |
950 | |
951 int | |
952 unified_range_table_nentries (void *unrangetab) | |
953 { | |
954 void *new_dest; | |
955 struct unified_range_table *un; | |
956 | |
957 align_the_damn_table (unrangetab); | |
958 new_dest = (char *) unrangetab + * (char *) unrangetab; | |
959 un = (struct unified_range_table *) new_dest; | |
960 return un->nentries; | |
961 } | |
962 | |
963 /* Return the OFFSETth range (counting from 0) in UNRANGETAB. */ | |
964 void | |
965 unified_range_table_get_range (void *unrangetab, int offset, | |
966 EMACS_INT *min, EMACS_INT *max, | |
967 Lisp_Object *val) | |
968 { | |
969 void *new_dest; | |
970 struct unified_range_table *un; | |
971 struct range_table_entry *tab; | |
972 | |
973 align_the_damn_table (unrangetab); | |
974 new_dest = (char *) unrangetab + * (char *) unrangetab; | |
975 un = (struct unified_range_table *) new_dest; | |
976 | |
977 assert (offset >= 0 && offset < un->nentries); | |
978 tab = (&un->first) + offset; | |
979 *min = tab->first; | |
980 *max = tab->last; | |
981 *val = tab->val; | |
4831
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
982 |
2e15c29cc2b3
fix bug in returning range table ends in unified range table code
Ben Wing <ben@xemacs.org>
parents:
4713
diff
changeset
|
983 internal_to_external_adjust_ends (un->type, min, max); |
428 | 984 } |
985 | |
986 | |
987 /************************************************************************/ | |
988 /* Initialization */ | |
989 /************************************************************************/ | |
990 | |
991 void | |
992 syms_of_rangetab (void) | |
993 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3017
diff
changeset
|
994 INIT_LISP_OBJECT (range_table); |
442 | 995 |
563 | 996 DEFSYMBOL_MULTIWORD_PREDICATE (Qrange_tablep); |
997 DEFSYMBOL (Qrange_table); | |
428 | 998 |
2421 | 999 DEFSYMBOL (Qstart_closed_end_open); |
1000 DEFSYMBOL (Qstart_open_end_open); | |
1001 DEFSYMBOL (Qstart_closed_end_closed); | |
1002 DEFSYMBOL (Qstart_open_end_closed); | |
1003 | |
428 | 1004 DEFSUBR (Frange_table_p); |
2421 | 1005 DEFSUBR (Frange_table_type); |
428 | 1006 DEFSUBR (Fmake_range_table); |
1007 DEFSUBR (Fcopy_range_table); | |
1008 DEFSUBR (Fget_range_table); | |
1009 DEFSUBR (Fput_range_table); | |
1010 DEFSUBR (Fremove_range_table); | |
1011 DEFSUBR (Fclear_range_table); | |
1012 DEFSUBR (Fmap_range_table); | |
1013 } | |
1014 | |
1015 void | |
1016 structure_type_create_rangetab (void) | |
1017 { | |
1018 struct structure_type *st; | |
1019 | |
1020 st = define_structure_type (Qrange_table, 0, rangetab_instantiate); | |
1021 | |
1022 define_structure_type_keyword (st, Qdata, rangetab_data_validate); | |
2421 | 1023 define_structure_type_keyword (st, Qtype, rangetab_type_validate); |
428 | 1024 } |