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 6 1712
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
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_Struc t;
struct Envelope
{
unsigned char processed; /* or bool */
struct Processed_Struc t 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.l earn.c-c++ faq: http://www.comeaucomputing.com/learn/faq/
Other sites: http://www.josuttis.com -- C++ STL Library book
"James Pascoe" <ja***@james-pascoe.com> wrote in message
news:fe******** *************** ***@posting.goo gle.com... 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.s tr-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
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.programmin g. 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
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.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
>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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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;
|
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 that, a structure definition that includes
function pointers only defines the function prototypes to be used with
them, but not the actual implementations, whereas in C++, member
functions cannot be changed *unless* virtual functions are used, or the
|
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 (myBranch + x) = new Branch(i); // it doesn't
x is a loop iterator, i is an int for the constructor to define an
array.
What am I doing wrong here.
|
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 a;klsdjf a;slkjdf a;skljdf a;slkjdf a;slkjf a;sklj fas;kl
jf;ak s</p>
| |
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
|
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 overhead (I
think). A Struct seems more appropriate. At least it is what I would
have used in other languages. But since a Struct *can* hold methods,
I wander if I am saving anything. If not, why use it?
|
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 "there is no difference between a struct
and a class except the public/private access specification" (and a few minor
other things). When I create a class, I always start by declaring the
default constructor, copy constructor and assignment operator...
|
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 I1388E497 LEVEL: Severe
PID : 7097 TID : 47556548689552PROC : db2agent
(MYDATABASE)
INSTANCE: db2inst1 NODE : 000 DB : MYDATABASE
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |