00001
00002
00003
00004 #include "common.h"
00005 #include "memgfx.h"
00006 #include "colHash.h"
00007
00008 static char const rcsid[] = "$Id: colHash.c,v 1.3 2003/05/06 07:33:41 kate Exp $";
00009
00010 struct colHash *colHashNew()
00011
00012 {
00013 struct colHash *cHash;
00014 AllocVar(cHash);
00015 cHash->freeEl = cHash->elBuf;
00016 return cHash;
00017 }
00018
00019 void colHashFree(struct colHash **pEl)
00020
00021 {
00022 freez(pEl);
00023 }
00024
00025 struct colHashEl *colHashAdd(struct colHash *cHash,
00026 unsigned r, unsigned g, unsigned b, int ix)
00027
00028 {
00029 struct colHashEl *che = cHash->freeEl++, **pCel;
00030 che->col.r = r;
00031 che->col.g = g;
00032 che->col.b = b;
00033 che->ix = ix;
00034 pCel = &cHash->lists[colHashFunc(r,g,b)];
00035 slAddHead(pCel, che);
00036 return che;
00037 }
00038
00039 struct colHashEl *colHashLookup(struct colHash *cHash,
00040 unsigned r, unsigned g, unsigned b)
00041
00042 {
00043 struct colHashEl *che;
00044 for (che = cHash->lists[colHashFunc(r,g,b)]; che != NULL; che = che->next)
00045 if (che->col.r == r && che->col.g == g && che->col.b == b)
00046 return che;
00047 return NULL;
00048 }
00049