Add DohSortedKeys function
Returns a list of sorted keys in a DOH Hash.
This commit is contained in:
parent
216b47320b
commit
77b08daca7
4 changed files with 29 additions and 26 deletions
|
|
@ -1244,6 +1244,14 @@ if an object was removed, 0 otherwise.
|
|||
Returns the list of hash table keys.
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<b><tt>List *SortedKeys(Hash *h, int (*cmp) (const DOH *, const DOH *))</tt></b>
|
||||
</p>
|
||||
|
||||
<div class="indent">
|
||||
Returns the list of sorted hash table keys.
|
||||
</div>
|
||||
|
||||
|
||||
<H3><a name="Extending_nn17">40.5.3 Lists</a></H3>
|
||||
|
||||
|
|
|
|||
|
|
@ -374,6 +374,18 @@ DOH *DohKeys(DOH *obj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohSortedKeys()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *DohSortedKeys(DOH *obj, int (*cmp) (const DOH *, const DOH *)) {
|
||||
DOHList *keys = DohKeys(obj);
|
||||
if (keys) {
|
||||
DohSortList(keys, cmp);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohGetInt()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#define DohSetattr DOH_NAMESPACE(Setattr)
|
||||
#define DohDelattr DOH_NAMESPACE(Delattr)
|
||||
#define DohKeys DOH_NAMESPACE(Keys)
|
||||
#define DohSortedKeys DOH_NAMESPACE(SortedKeys)
|
||||
#define DohGetInt DOH_NAMESPACE(GetInt)
|
||||
#define DohGetDouble DOH_NAMESPACE(GetDouble)
|
||||
#define DohGetChar DOH_NAMESPACE(GetChar)
|
||||
|
|
@ -201,6 +202,7 @@ extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_c
|
|||
extern int DohDelattr(DOH *obj, const DOHString_or_char *name);
|
||||
extern int DohCheckattr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *value);
|
||||
extern DOH *DohKeys(DOH *obj);
|
||||
extern DOH *DohSortedKeys(DOH *obj, int (*cmp) (const DOH *, const DOH *));
|
||||
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
|
||||
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
|
||||
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
|
||||
|
|
@ -444,6 +446,7 @@ extern void DohMemoryDebug(void);
|
|||
#define FileErrorDisplay DohFileErrorDisplay
|
||||
#define NewVoid DohNewVoid
|
||||
#define Keys DohKeys
|
||||
#define SortedKeys DohSortedKeys
|
||||
#define Strcmp DohStrcmp
|
||||
#define Strncmp DohStrncmp
|
||||
#define Strstr DohStrstr
|
||||
|
|
|
|||
|
|
@ -1963,26 +1963,6 @@ int SwigType_issubtype(const SwigType *t1, const SwigType *t2) {
|
|||
return r;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* compare_strings()
|
||||
*
|
||||
* Helper function to sort a list of strings
|
||||
* ----------------------------------------------------------------------------- */
|
||||
static int compare_strings(const DOH *a, const DOH *b) {
|
||||
return strcmp((char *) Data(a), (char *) Data(b));
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* sorted_list_from_hash()
|
||||
*
|
||||
* Returns a sorted list of the keys in the given hash
|
||||
* ----------------------------------------------------------------------------- */
|
||||
static List *sorted_list_from_hash(Hash *h) {
|
||||
List *l = Keys(h);
|
||||
SortList(l, compare_strings);
|
||||
return l;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigType_inherit_equiv()
|
||||
*
|
||||
|
|
@ -2004,7 +1984,7 @@ void SwigType_inherit_equiv(File *out) {
|
|||
if (!subclass)
|
||||
subclass = NewHash();
|
||||
|
||||
r_resolved_sorted_keys = sorted_list_from_hash(r_resolved);
|
||||
r_resolved_sorted_keys = SortedKeys(r_resolved, Strcmp);
|
||||
rk = First(r_resolved_sorted_keys);
|
||||
while (rk.item) {
|
||||
List *sub_sorted_keys;
|
||||
|
|
@ -2028,7 +2008,7 @@ void SwigType_inherit_equiv(File *out) {
|
|||
/* Printf(stdout,"rk.item = '%s'\n", rk.item);
|
||||
Printf(stdout,"rh = %p '%s'\n", rh,rh); */
|
||||
|
||||
sub_sorted_keys = sorted_list_from_hash(sub);
|
||||
sub_sorted_keys = SortedKeys(sub, Strcmp);
|
||||
bk = First(sub_sorted_keys);
|
||||
while (bk.item) {
|
||||
prefix = SwigType_prefix(rk.item);
|
||||
|
|
@ -2165,7 +2145,7 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
|
||||
Printf(f_forward, "\n/* -------- TYPES TABLE (BEGIN) -------- */\n\n");
|
||||
|
||||
mangled_list = sorted_list_from_hash(r_mangled);
|
||||
mangled_list = SortedKeys(r_mangled, Strcmp);
|
||||
for (ki = First(mangled_list); ki.item; ki = Next(ki)) {
|
||||
List *el;
|
||||
Iterator ei;
|
||||
|
|
@ -2231,7 +2211,7 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
}
|
||||
|
||||
/* now build nt */
|
||||
ntlist = sorted_list_from_hash(nthash);
|
||||
ntlist = SortedKeys(nthash, Strcmp);
|
||||
ltiter = First(ntlist);
|
||||
nt = 0;
|
||||
while (ltiter.item) {
|
||||
|
|
@ -2259,7 +2239,7 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
Printf(types, "\"%s\", \"%s\", 0, 0, (void*)%s, 0};\n", ki.item, nt, cd);
|
||||
|
||||
el = SwigType_equivalent_mangle(ki.item, 0, 0);
|
||||
SortList(el, compare_strings);
|
||||
SortList(el, Strcmp);
|
||||
for (ei = First(el); ei.item; ei = Next(ei)) {
|
||||
String *ckey;
|
||||
String *conv;
|
||||
|
|
@ -2289,7 +2269,7 @@ void SwigType_emit_type_table(File *f_forward, File *f_table) {
|
|||
Delete(nt);
|
||||
}
|
||||
/* print the tables in the proper order */
|
||||
SortList(table_list, compare_strings);
|
||||
SortList(table_list, Strcmp);
|
||||
i = 0;
|
||||
for (ki = First(table_list); ki.item; ki = Next(ki)) {
|
||||
Printf(f_forward, "#define SWIGTYPE%s swig_types[%d]\n", ki.item, i++);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue