* bit map routines (in-core).
*/
/*
- * Copyright (c) 1995, 1996 Marcus D. Watts All rights reserved.
+ * Copyright (c) 1995, 1996, 2007 Marcus D. Watts All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Marcus D. Watts.
- * 4. The name of the developer may not be used to endorse or promote
+ * 3. The name of the developer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
struct bitmap {
struct bitmap *m_next;
int m_page;
- long m_data[MDATA];
+ int m_data[MDATA];
};
-#define MAP(p) ((struct bitmap*)((long)(p)&~1))
+#define MAP(p) ((struct bitmap*)((int)(p)&~1))
#define NEGMAP(p) (((int)(p))&1)
#define POSMAP(p) (!NEGMAP(p))
-#define NOT_MAP(mp) ((struct map *) (((long)(mp)) ^ 1))
+#define NOT_MAP(mp) ((struct map *) (((int)(mp)) ^ 1))
#define NUMBERTOBIT(n) ((n) & ((1<<LSHIFT)-1))
#define NUMBERTOINDEX(n) ((n>>LSHIFT) & ((1<<MSHIFT)-1))
extern int debug_mask;
int
-in_map(struct map *parm, long node)
+in_map(struct map *parm, int node)
{
struct bitmap *map;
- long bit;
+ int bit;
int x, page;
int result;
if (Aflag)
if (TONUMBER(page, x, bit) != node) {
printf
- ("bxp mixup: node=%ld -> p=%d x=%d b=%d -> %ld, %ld, %ld = %ld\n",
+ ("bxp mixup: node=%d -> p=%d x=%d b=%d -> %d, %d, %d = %d\n",
node, page, x, bit, TONUMBER(page, 0, 0), TONUMBER(0, x, 0),
TONUMBER(0, 0, bit), TONUMBER(page, x, bit));
}
}
struct map *
-add_map(struct map *parm, long node)
+add_map(struct map *parm, int node)
{
struct bitmap *map;
- long bit;
+ int bit;
int x, page;
#ifdef MAP_DEBUG
return 0;
}
map->m_page = page;
- bzero((char *)map->m_data, sizeof map->m_data);
+ memset((char *) map->m_data, 0, sizeof map->m_data);
if (NEGMAP(parm)) {
int i;
for (i = 0; i < MDATA; ++i)
{
struct bitmap **mpp, *mp2;
int i;
- for (mpp = ↦ mp2 = *mpp;) {
+ for (mpp = ↦ (mp2 = *mpp);) {
for (i = 0; i < MDATA; ++i)
- if (map->m_data[i])
+ if (mp2->m_data[i])
break;
if (i == MDATA) {
#ifdef PRINT_MAP_ERROR
struct bitmap **rightmp, *lmap, *rmap;
int i;
for (lmap = left; lmap; lmap = lmap->m_next) {
- for (rightmp = &right; rmap = *rightmp; rightmp = &rmap->m_next)
+ for (rightmp = &right; (rmap = *rightmp); rightmp = &rmap->m_next)
if (rmap->m_page == lmap->m_page) {
for (i = 0; i < MDATA; ++i)
lmap->m_data[i] |= rmap->m_data[i];
break;
}
}
- for (rightmp = &left; *rightmp; rightmp = &(*rightmp)->m_next);
+ for (rightmp = &left; *rightmp; rightmp = &(*rightmp)->m_next)
+ ;
*rightmp = right;
return left;
}
{
struct bitmap **rightmp, *lmap, *rmap, **leftmp;
int i;
- long sig;
- for (leftmp = &left; lmap = *leftmp;) {
+ int sig;
+ for (leftmp = &left; (lmap = *leftmp);) {
sig = 0;
- for (rightmp = &right; rmap = *rightmp; rightmp = &rmap->m_next)
+ for (rightmp = &right; (rmap = *rightmp); rightmp = &rmap->m_next)
if (rmap->m_page == lmap->m_page) {
for (i = 0; i < MDATA; ++i)
sig |= (lmap->m_data[i] &= rmap->m_data[i]);
{
struct bitmap **rightmp, *lmap, *rmap, **leftmp;
int i;
- long sig;
+ int sig;
#ifdef MAP_DEBUG
if (Mflag) {
- printf("bic_bitmap: left=%#lx right=%#lx\n", left, right);
+ printf("bic_bitmap: left=%#lx right=%#lx\n", (long)left, (long)right);
}
#endif
- for (leftmp = &left; lmap = *leftmp;) {
+ for (leftmp = &left; (lmap = *leftmp);) {
sig = 0;
- for (rightmp = &right; rmap = *rightmp; rightmp = &rmap->m_next)
+ for (rightmp = &right; (rmap = *rightmp); rightmp = &rmap->m_next)
if (rmap->m_page == lmap->m_page) {
for (i = 0; i < MDATA; ++i)
sig |= (lmap->m_data[i] &= ~rmap->m_data[i]);
left = simplify_bitmap(left);
#ifdef MAP_DEBUG
if (Mflag) {
- printf("bic_bitmap: result=%#lx\n", left);
+ printf("bic_bitmap: result=%#lx\n", (long) left);
}
#endif
return left;
#endif
if (POSMAP(mp1))
if (POSMAP(mp2))
- mp1 = (struct map *)and_bitmap(mp1, mp2);
+ mp1 = (struct map *)and_bitmap((struct bitmap *) mp1,
+ (struct bitmap *) mp2);
else
- mp1 = (struct map *)bic_bitmap(mp1, MAP(mp2));
+ mp1 = (struct map *)bic_bitmap((struct bitmap *) mp1, MAP(mp2));
else if (POSMAP(mp2))
- mp1 = (struct map *)bic_bitmap(mp2, MAP(mp1));
+ mp1 = (struct map *)bic_bitmap((struct bitmap *) mp2, MAP(mp1));
else
mp1 = NOT_MAP(or_bitmap(MAP(mp1), MAP(mp2)));
#ifdef MAP_DEBUG
#endif
if (POSMAP(mp1))
if (POSMAP(mp2))
- mp1 = (struct map *)or_bitmap(mp1, mp2);
+ mp1 = (struct map *)or_bitmap((struct bitmap *) mp1,
+ (struct bitmap *) mp2);
else
- mp1 = NOT_MAP(bic_bitmap(MAP(mp2), mp1));
+ mp1 = NOT_MAP(bic_bitmap(MAP(mp2), (struct bitmap *) mp1));
else if (POSMAP(mp2))
- mp1 = NOT_MAP(bic_bitmap(MAP(mp1), mp2));
+ mp1 = NOT_MAP(bic_bitmap(MAP(mp1), (struct bitmap *) mp2));
else
mp1 = NOT_MAP(and_bitmap(MAP(mp1), MAP(mp2)));
#ifdef MAP_DEBUG
}
#endif
map = MAP(parm);
- for (mpp = &result; *mpp = 0, map; map = map->m_next) {
+ for (mpp = &result; (*mpp = 0), map; map = map->m_next) {
*mpp = (struct bitmap *)malloc(sizeof **mpp);
if (!*mpp) {
#ifdef MAP_DEBUG
return (struct map *)result;
}
-long
+int
count_map(struct map *parm)
{
- long nf;
+ int nf;
struct bitmap *map;
- register i, j;
+ int i, j;
nf = 0;
for (map = MAP(parm); map; map = map->m_next) {
for (i = 0; i < MDATA; ++i) {
- if (!map->m_data[i]);
+ if (!map->m_data[i])
+ ;
else if (!~map->m_data[i])
nf += (1 << LSHIFT);
else
return nf;
}
-long
-next_map(struct map *parm, long node)
+int
+next_map(struct map *parm, int node)
{
struct bitmap *map, *lowest;
- long bit, mask;
+ int bit, mask;
int x, page;
int best;
int i;
if (Aflag) {
if (bn == (1 << LSHIFT)) {
printf
- ("next_map: botch; pageno %d index %d data %#lx mask %#lx x,bit %d,%#lx\n",
+ ("next_map: botch; pageno %d index %d data %#x mask %#x x,bit %d,%#x\n",
map->m_page, i, map->m_data[i], mask, x, bit);
continue;
}
#ifdef MAP_DEBUG
if (Aflag) {
printf(" -> %d\n", best);
- if (best >= 0 && !in_map((struct map *)parm, best)) {
+ if (best >= 0 && !in_map(parm, best)) {
printf("next_map: botch; %d not in map\n", best);
return -1;
}
return best;
}
-long
+int
first_map(struct map *parm)
{
return next_map(parm, -9999);
}
-long
-prev_map(struct map *parm, long node)
+int
+prev_map(struct map *parm, int node)
{
struct bitmap *map, *lowest;
- long bit, mask;
+ int bit, mask;
int x, page;
int best;
int i;
}
if (node < 0)
- node = ((unsigned long)~0) >> 1;
+ node = ((unsigned int)~0) >> 1;
--node;
bit = NUMBERTOBIT(node);
if (Aflag) {
if (bn < 0) {
printf
- ("prev_map: botch; pageno %d index %d data %#lx mask %#lx x,bit %d,%#lx\n",
+ ("prev_map: botch; pageno %d index %d data %#x mask %#x x,bit %d,%#x\n",
map->m_page, i, map->m_data[i], mask, x, bit);
continue;
}
return best;
}
-long
+int
last_map(struct map *parm)
{
return prev_map(parm, 0x7fffffff);
}
map = MAP(parm);
if (!map)
- printf(" nil(%lx)", parm);
+ printf(" nil(%lx)", (long)parm);
else
- printf(" %lx", parm);
+ printf(" %lx", (long)parm);
lastbitno = -100;
firstbitno = -100;
for (; map; map = map->m_next)
#ifdef NEED_READ_WRITE
struct map *
-read_map(int (*f) (), char *arg)
+read_map(int (*f) (void *), char *arg)
{
struct bitmap *map, *result, **mp;
int page;
- int bitno, lastno, thisno, prevno;
- int i, j;
+ int bitno, lastno;
int data;
/* count, then startbitno, then bits. */
continue;
page = NUMBERTOPAGE(bitno);
if (!map || map->m_page != page)
- for (mp = &result; map = *mp; mp = &map->m_next)
+ for (mp = &result; (map = *mp); mp = &map->m_next)
if (map->m_page == page)
break;
if (!map) {
free_map((struct map *)result);
return 0;
}
- bzero((char *)map->m_data, sizeof map->m_data);
+ memset((char *) map->m_data, 0, sizeof map->m_data);
map->m_page = page;
map->m_next = 0;
*mp = map;
}
int
-write_map(struct map *parm, int (*f) (), char *arg)
+write_map(struct map *parm, int (*f) (void *, int), char *arg)
{
struct bitmap *map;
int page;
* map.h - header routines for in-core bitmap routines.
*/
/*
- * Copyright (c) 1995 Marcus D. Watts All rights reserved.
+ * Copyright (c) 1995, 2007 Marcus D. Watts All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Marcus D. Watts.
- * 4. The name of the developer may not be used to endorse or promote
+ * 3. The name of the developer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
struct map;
-int in_map(struct map *, long);
+int in_map(struct map *, int);
void free_map(struct map *);
-struct map *add_map(struct map *, long);
+struct map *add_map(struct map *, int);
struct map *and_map(struct map *, struct map *);
struct map *or_map(struct map *, struct map *);
struct map *not_map(struct map *);
struct map *copy_map(struct map *);
-long count_map(struct map *);
-long next_map(struct map *, long);
-long first_map(struct map *);
-long prev_map(struct map *, long);
-long last_map(struct map *);
+int count_map(struct map *);
+int next_map(struct map *, int);
+int first_map(struct map *);
+int prev_map(struct map *, int);
+int last_map(struct map *);
struct map *negative_map(struct map *);
struct map *bic_map(struct map *, struct map *);
int print_map(struct map *);