473,473 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Implement set for generate data type?

Hi,

I'm searching for an implementation of set. I want to insert or delete
elements. The set should have no redudant element. It seems linked list
is one way for implementing set.

But I don't have any experence how to handle the C++ concept "templete"
in C. That is how to make the implemetation adaptable to different data
types.

Would you please point me some references? I'll also be glad, if you
can show me any implemenations of set in C. Thanks!

Best wishes,
Peng

Nov 14 '05 #1
5 2042
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pe*******@gmail.com wrote:
Hi,

I'm searching for an implementation of set. I want to insert or delete
elements. The set should have no redudant element. It seems linked list
is one way for implementing set.

But I don't have any experence how to handle the C++ concept "templete"
in C. That is how to make the implemetation adaptable to different data
types.

Would you please point me some references? I'll also be glad, if you
can show me any implemenations of set in C. Thanks!


Here's some hints...

union AllElements {
char Character;
unsigned int UnsignedInt;
unsigned long UnsignedLong;
float FloatPoint;
double LongFloatPoint;
};
struct A_Set_Element {
{
struct A_Set_Element *Next;
int Type;
union AllElements Valu;
};

and

#include <stdio.h>
void SayElementType(struct A_Set_Element *Element)
{
switch (Element->Type)
{
case 0: /* Character */
printf("Set Element is Character - value is '%c'\n",
Element->Valu.Character);
break;

case 1: /* UnsignedInt */
printf("Set Element is UnsignedInt - value is '%u'\n",
Element->Valu.UnsignedInt);
break;

/* and so on */
}
}


- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCsh5LagVFX4UWr64RAg0JAJ45C4I9MwEh+r3Ns/+UovuhKJ/yTQCgvp59
cZwmsOL+1pT43S8PtFeFj3c=
=dpZp
-----END PGP SIGNATURE-----
Nov 14 '05 #2


Lew Pitcher wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pe*******@gmail.com wrote:
Hi,

I'm searching for an implementation of set. I want to insert or delete
elements. The set should have no redudant element. It seems linked list
is one way for implementing set.

But I don't have any experence how to handle the C++ concept "templete"
in C. That is how to make the implemetation adaptable to different data
types.

Would you please point me some references? I'll also be glad, if you
can show me any implemenations of set in C. Thanks!


Here's some hints...

union AllElements {
char Character;
unsigned int UnsignedInt;
unsigned long UnsignedLong;
float FloatPoint;
double LongFloatPoint;
};
struct A_Set_Element {
{
struct A_Set_Element *Next;
int Type;
union AllElements Valu;
};

and

#include <stdio.h>
void SayElementType(struct A_Set_Element *Element)
{
switch (Element->Type)
{
case 0: /* Character */
printf("Set Element is Character - value is '%c'\n",
Element->Valu.Character);
break;

case 1: /* UnsignedInt */
printf("Set Element is UnsignedInt - value is '%u'\n",
Element->Valu.UnsignedInt);
break;

/* and so on */
}
}

Is it possible to use void pointer to point to the data? I think it is
easier to use than define union structures. Thanks!

Nov 14 '05 #3

Le 17/06/2005 02:50, dans l6******************@news20.bellglobal.com, «*Lew
Pitcher*» <lp******@sympatico.ca> a écrit*:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pe*******@gmail.com wrote:
Hi,

I'm searching for an implementation of set. I want to insert or delete
elements. The set should have no redudant element. It seems linked list
is one way for implementing set.

But I don't have any experence how to handle the C++ concept "templete"
in C. That is how to make the implemetation adaptable to different data
types.

Would you please point me some references? I'll also be glad, if you
can show me any implemenations of set in C. Thanks!


It's more on-topic on comp.programming I think, but just a suggestion,
you should probably use hash tables, for faster access. But maybe another
data structure is best, it greatly depends on your data. Linked list are
not very good since they need O(N) to access, with N the list length (but
insertion is fast). Other structures likes hashes, trees or B-trees may
be more suited. There are great textbooks on data structures:
"Aho, Hopcroft, Ullmann", "Cormen, Leiserson, Rivest, Stein", and "Knuth"
Among others. Google knows the titles :-)

Nov 14 '05 #4
Jean-Claude Arbaut wrote:
Le 17/06/2005 02:50, dans l6******************@news20.bellglobal.com, «Lew
Pitcher » <lp******@sympatico.ca> a écrit :

It's more on-topic on comp.programming I think, but just a suggestion,
you should probably use hash tables, for faster access. But maybe another
data structure is best, it greatly depends on your data. Linked list are
not very good since they need O(N) to access, with N the list length (but
insertion is fast). Other structures likes hashes, trees or B-trees may
be more suited. There are great textbooks on data structures:
"Aho, Hopcroft, Ullmann", "Cormen, Leiserson, Rivest, Stein", and "Knuth"
Among others. Google knows the titles :-)


For my specific application, N is less than some small threshold. So
the efficiency of the implementation is not very important to me. The
problem for me is that there are several data type that I have to put
into several sets. My concern is how to implement a generic set data
stucture such that I can put any type of data in it.

Nov 14 '05 #5

<Pe*******@gmail.com> wrote
Here's some hints...

union AllElements {
char Character;
unsigned int UnsignedInt;
unsigned long UnsignedLong;
float FloatPoint;
double LongFloatPoint;
};


Is it possible to use void pointer to point to the data? I think it is
easier to use than define union structures. Thanks!

That's the route to go down.
In reality you seldom want to store basic types in a set (I presume you mean
the C++ stl set, but the term doesn't have an agreed programming meaning).

Your choice is, store pointers and effectively require all elements to be
allocated with malloc(), or store elements of arbitrary size and pass the
size in to the structure, treating them internally as arrays of unsigned
chars.

Neither method is perfect, which is why C++ introduced templates. The
pointer method is inefficient for small structures, whilst the pass the size
method is inefficinet when the elements you wnat to store are pointers
anyway.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: fivelitermustang | last post by:
Essentially what the program needs to do is split apart a large group of data and then it further splits apart the groups of data, etc... For example, Level 0 starts off with a large array data....
21
by: Morten Aune Lyrstad | last post by:
I wish to create my own assembly language for script. For now it is mostly for fun and for the sake of the learning, but I am also creating a game engine where I want this system in. Once the...
11
by: Gent | last post by:
I have a table named Holding_Value that has several fields in it among which are UID, fkHolding, EffDate, Units, MarketValue, AssetPrice. UID is an identity field and fkHolding is a foreign key to...
5
by: Kevin | last post by:
I am developing a web site with PHP and MySQL. There are many forms that need to be generated based on users' information in database, and then let users to complete the rest. Finally the users...
4
by: Chris Bower | last post by:
Reposted from aspnet.buildingcontrols: Ok, I've got a bunch of derived controls that all have a property Rights of type Rights (Rights is an Enumerator). I wrote a custom TypeConverter so that I...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
2
by: Swapnil2006 | last post by:
I am using the SOAP 1.1 request and response to create a corresponding web method for it. SOAP 1.1 response looks like as follows : <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
11
by: Bob Altman | last post by:
Hi all, I want to write a generic class that does this: Public Class X (Of T) Public Sub Method(param As T) dim x as T = param >3 End Sub End Class
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.