MARKING STRUCTS PROCESSED

J

James Pascoe

Dear All,

Apologies if this is OT.

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

Thanks in advance,

James
 
E

Eric Sosman

James said:
Dear All,

Apologies if this is OT.

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

This doesn't seem to be a C question, and there are
probably more appropriate newsgroups. Nonetheless, I'll
suggest a few approaches:

1: You've already considered and rejected putting a
marker of some kind in the struct itself.

2: If you are in control of the hash table implementation,
perhaps you could put your markers in the table itself.

3: Use two hash tables, and move the processed items
from one to the other. When you search for an arbitrary
item, search both tables.

4: Use a second hash table containing pointers to the
processed items. To determine whether a given item has or
has not been processed, look it up in the auxiliary table.
 
T

Thomas Matthews

James said:
Dear All,

Apologies if this is OT.

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

Thanks in advance,

James

Use a super-structure which contains a 'processed' flag and either
the structure processed or a pointer to the processed structure.

struct Processed_Struct;

struct Envelope
{
unsigned char processed; /* or bool */
struct Processed_Struct content;
};


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
T

Toni Uusitalo

James Pascoe said:
Dear All,

Apologies if this is OT.

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

If you have malloc'ed string members in your struct you could use (some
would say)
an ugly hack of allocating 1 byte too much for the string and setting that
string's
first byte to be the "processed" flag. Of course you must remember to
free(mystruct.str-1);
in that case.

Or you could use some Reserved member in you structs. Name it like
dwReserved or fReserved (common way in winAPI) and you'll get everyone's
sympathy too ;-)

with respect,
Toni Uusitalo
 
C

CBFalconer

James said:
Apologies if this is OT.

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

It is OT on c.l.c, and more suited to comp.programming. However,
take a look at:

<http://cbfalconer.home.att.net/download/hashlib.zip>

and the demonstrations of its use, including markov and wdfreq.
 
J

Jack Klein

Dear All,

Apologies if this is OT.

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

Thanks in advance,

James

You could use a hash algorithm that generates an unsigned hash value
using one bit less than the size of the data type. For example, if
your longs are 32 bits, generate 32 bit hash values, then left shift
them by one bit for use.

When you process a structure, set the least significant bit of the
hash code by oring in 1UL.

Of course all your other hash code would need to ignore the least
significant bit.
 
G

Gordon Burditt

I have a C program which processes an arbitrary number of structs that
are stored in a hash table. (The nature of the processing and the
layout of the structs is irrelevant to this post, so I wont bore you
with the details).

My problem is that I need some way of distinguishing the processed
structs from those that are unprocessed. Obviously, I can add a
`processed' field to the struct definition - but, I don't want to do
this as the struct is part of a public API and I want to keep internal
details hidden.

Also, I could have some other form of data structure - to keep track
of what has been processed, but ideally, I would like to avoid or at
best minimise the additional complexity. Whatsmore, I need to keep the
original structs in the hash table.

Has anybody got a really neat solution to this ?

Store the pointers (in printable form, using sprintf() with "%p"
format) in the large SQL database in a Microsoft sub-dungeon. If
it's listed in the SQL table, it's processed. If it's not, it
isn't. (This might be the same database that malloc() and free()
use). Microsoft will, of course, charge for this service and
probably take your first-born child with the EULA.

Gordon L. Burditt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top