The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 11:14 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 04:01 PM
Copying a Directory Structure to a new structure jhansrod UNIX for Dummies Questions & Answers 8 07-27-2005 06:24 AM
if then else structure props UNIX for Dummies Questions & Answers 4 12-27-2003 06:50 AM
Ram structure Dorian HP-UX 1 11-05-2002 09:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2008
dhanamurthy dhanamurthy is offline
Registered User
  
 

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
  #2 (permalink)  
Old 03-26-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
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.
  #3 (permalink)  
Old 03-26-2008
dhanamurthy dhanamurthy is offline
Registered User
  
 

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
  #4 (permalink)  
Old 03-27-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0