The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help in Directory Structure murtaza Shell Programming and Scripting 5 03-29-2007 08:14 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 01:01 PM
Copying a Directory Structure to a new structure jhansrod UNIX for Dummies Questions & Answers 8 07-27-2005 03:24 AM
if then else structure props UNIX for Dummies Questions & Answers 4 12-27-2003 03:50 AM
Ram structure Dorian HP-UX 1 11-05-2002 06:48 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-26-2008
Read Only
 

Join Date: Jun 2006
Posts: 105
Search attributes in one structure using the values from another structure

Hello Groups

I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records.

if we loop it in both the structures it is going to consume time.
I am looking for a simple algorithm where i can implement it easily.

For eg)

struct x
{
char empname[20] ;
int empno;
int deptno;
}x1;

struct y
{
char deptname[20];
int deptno;

}y1;

Structure x can be in a list where it contains say 1000 records and similaraly y.
I need to search the deptno of x in deptno of y.

Reply me if you have ideas.


Regards
Dhanamurthy
Reply With Quote
Forum Sponsor
  #2  
Old 03-26-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
I don't see any way to avoid this being an O(n) operation with linked lists.
Using a chained hash table based on the character string would cut the overhead drastically.
Reply With Quote
  #3  
Old 03-26-2008
Read Only
 

Join Date: Jun 2006
Posts: 105
I also have another idea as to
put the two files in a List and do a binary search from the input of one of the List. Not sure if there is a performance issue in this way.

Can you please let me know what is chain hashing by an example?
I am not clear on how to avoid the overhead.

Regards
Dhanamurthy
Reply With Quote
  #4  
Old 03-27-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
The idea of a chained hash table is simple.
Given a key (character array) compute in a 'table' the location to which
the character string hashes using a hash value derived from the key.
Code:
void placenode(void **arr, void *node, char *key, int arrsz) {
int p = 0;
struct typewhatever *datum;

                   while (*key != '\0') {p += (31 + *key); key++;}
                   datum = arr[p % arrsz];
                   append_node(datum,node); 
}
From this one can search the array and 'bucket' for matches based on a restricted
subset of identically hashed values.

HTH.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0