472,989 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

MARKING STRUCTS PROCESSED

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
6 1642
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
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

"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
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
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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Spartanicus | last post by:
How to get help from this group, and how to construct a minimised test case: http://www.spartanicus.utvinternet.ie/help_us_help_you.htm -- Spartanicus
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
5
by: Bilgehan.Balban | last post by:
Hi, I am currently brushing up my c++ knowledge and I would like to ask you about the differences between classes and C structs, in the function/method perspective. 1) Is it correct to say...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
2
by: noblEnds | last post by:
Hi. A quick thanks to those who try to help. here's what i'm trying to do: <?xml> <stuff> <theStory> <p>aaklsjd fakljs fakjs faskldj a;klsjdf l;aksdj f THIS TEXT SHOULD BE HIGHLIGHED...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
29
by: Dom | last post by:
I'm really confused by the difference between a Struct and a Class? Sometimes, I want just a group of fields to go together. A Class without methods seems wrong, in that it carries too much...
43
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
0
by: Nokao | last post by:
I'm having a lot of severe errors in my db2diag.log, (DB2 v9.1.0.0). Googling I don't fin any information :( What can I do? I attach the first reports...: 2007-11-19-17.50.26.379948+060...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.