By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

MARKING STRUCTS PROCESSED

P: n/a
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
Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
James Pascoe wrote:
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.

--
Er*********@sun.com

Nov 14 '05 #2

P: n/a
James Pascoe wrote:
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

Nov 14 '05 #3

P: n/a

"James Pascoe" <ja***@james-pascoe.com> wrote in message
news:fe**************************@posting.google.c om...
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
Nov 14 '05 #4

P: n/a
James Pascoe wrote:

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.

--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02
Nov 14 '05 #5

P: n/a
On 8 Sep 2004 07:11:40 -0700, ja***@james-pascoe.com (James Pascoe)
wrote in comp.lang.c:
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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #6

P: n/a
>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
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.