From ee259e3ad3885942a50b58fafe41e71385eab615 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Tue, 18 Dec 2007 21:09:58 +0000 Subject: [PATCH] One-valued types for media number. They can be encoded in the schema, no need for storing 1, 2 or 3 all the time. --- src/attr_store.c | 21 +++++++++++++++++++++ src/attr_store.h | 1 + src/attr_store_p.h | 1 + src/pool.h | 10 +++++++++- tools/dumpattr.c | 3 +++ tools/repo_susetags.c | 6 +++--- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/attr_store.c b/src/attr_store.c index 3d9e2d5..85978dd 100644 --- a/src/attr_store.c +++ b/src/attr_store.c @@ -154,6 +154,19 @@ add_attr_int (Attrstore *s, unsigned int entry, Id name, unsigned int val) add_attr (s, entry, nv); } +void +add_attr_special_int (Attrstore *s, unsigned int entry, Id name, unsigned int val) +{ + if (val > (TYPE_ATTR_SPECIAL_END - TYPE_ATTR_SPECIAL_START)) + add_attr_int (s, entry, name, val); + else + { + LongNV nv; + nv.key = add_key (s, name, TYPE_ATTR_SPECIAL_START + val, 0); + add_attr (s, entry, nv); + } +} + static void add_attr_chunk (Attrstore *s, unsigned int entry, Id name, unsigned int ofs, unsigned int len) { @@ -342,6 +355,11 @@ add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap, } break; default: + if (type >= TYPE_ATTR_SPECIAL_START && type <= TYPE_ATTR_SPECIAL_END) + { + add_attr_special_int (s, entry, name, type - TYPE_ATTR_SPECIAL_START); + break; + } pool_debug(pool, SAT_FATAL, "unknown type %d\n", type); exit(0); } @@ -781,6 +799,9 @@ attr_store_unpack (Attrstore *s) break; } default: + if (ai.type >= TYPE_ATTR_SPECIAL_START + && ai.type <= TYPE_ATTR_SPECIAL_END) + add_attr_special_int (s, i, ai.name, ai.type - TYPE_ATTR_SPECIAL_START); break; } } diff --git a/src/attr_store.h b/src/attr_store.h index 61ab5b1..657b5b6 100644 --- a/src/attr_store.h +++ b/src/attr_store.h @@ -33,6 +33,7 @@ LocalId str2localid (Attrstore *s, const char *str, int create); const char * localid2str(Attrstore *s, LocalId id); void add_attr_int (Attrstore *s, unsigned int entry, Id name, unsigned int val); +void add_attr_special_int (Attrstore *s, unsigned int entry, Id name, unsigned int val); void add_attr_blob (Attrstore *s, unsigned int entry, Id name, const void *ptr, unsigned int len); void add_attr_string (Attrstore *s, unsigned int entry, Id name, const char *val); void add_attr_intlist_int (Attrstore *s, unsigned int entry, Id name, int val); diff --git a/src/attr_store_p.h b/src/attr_store_p.h index 4760af0..6258aed 100644 --- a/src/attr_store_p.h +++ b/src/attr_store_p.h @@ -185,6 +185,7 @@ ai_step (Attrstore *s, attr_iterator *ai) break; } default: + /* ??? Convert TYPE_ATTR_SPECIAL_* to _INT type with the right value? */ break; } return 1; diff --git a/src/pool.h b/src/pool.h index 4042a04..261c7c2 100644 --- a/src/pool.h +++ b/src/pool.h @@ -142,11 +142,19 @@ struct _Pool { #define TYPE_COUNT_NAMED 11 #define TYPE_COUNTED 12 -#define TYPE_ATTR_TYPE_MAX 12 #define TYPE_IDVALUEARRAY 13 #define TYPE_IDVALUEVALUEARRAY 14 +/* The special types are usable to encode one-valued attributes, they have + no associated data. This is useful to encode values which many solvables + have in common, and whose overall set is relatively limited. A prime + example would be the media number. Be warned: careless use of this + leads to combinatoric explosion of number of schemas. */ +#define TYPE_ATTR_SPECIAL_START 15 +#define TYPE_ATTR_SPECIAL_END (TYPE_ATTR_SPECIAL_START + 31) +#define TYPE_ATTR_TYPE_MAX TYPE_ATTR_SPECIAL_END + //----------------------------------------------- diff --git a/tools/dumpattr.c b/tools/dumpattr.c index b59400b..5930f1c 100644 --- a/tools/dumpattr.c +++ b/tools/dumpattr.c @@ -71,6 +71,9 @@ dump_attrs (Attrstore *s, unsigned int entry) break; } default: + if (ai.type >= TYPE_ATTR_SPECIAL_START + && ai.type <= TYPE_ATTR_SPECIAL_END) + fprintf (stdout, "spec %d", ai.type - TYPE_ATTR_SPECIAL_START); fprintf (stdout, "\n"); break; } diff --git a/tools/repo_susetags.c b/tools/repo_susetags.c index 932d881..b4c9fc3 100644 --- a/tools/repo_susetags.c +++ b/tools/repo_susetags.c @@ -159,7 +159,7 @@ add_location (char *line, Solvable *s, unsigned entry) { /* medianr filename dir don't optimize this one */ - add_attr_int (attr, entry, str2id (pool, "medianr", 1), atoi (sp[0])); + add_attr_special_int (attr, entry, str2id (pool, "medianr", 1), atoi (sp[0])); add_attr_localids_id (attr, entry, str2id (pool, "mediadir", 1), str2localid (attr, sp[2], 1)); add_attr_string (attr, entry, str2id (pool, "mediafile", 1), sp[1]); return; @@ -190,12 +190,12 @@ add_location (char *line, Solvable *s, unsigned entry) break; if (*n2 || strcmp (n1, ".rpm")) goto nontrivial; - add_attr_int (attr, entry, str2id (pool, "medianr", 1), medianr); + add_attr_special_int (attr, entry, str2id (pool, "medianr", 1), medianr); add_attr_void (attr, entry, str2id (pool, "mediafile", 1)); return; nontrivial: - add_attr_int (attr, entry, str2id (pool, "medianr", 1), medianr); + add_attr_special_int (attr, entry, str2id (pool, "medianr", 1), medianr); add_attr_string (attr, entry, str2id (pool, "mediafile", 1), sp[1]); return; } -- 2.7.4