searching in a huge data pool?

K

kids

Hi all,
i have 2 files, 1 file that store 1000 records of name entries and
it's key ID. With the sorting function all the records have been sorted and
its correspond key id was store in a sorted file. If 1 of record has been
deleted, i have to keep looping the sorted file to find the deleted record
Key Id and delete it. Any better way instead of using for loop to find the
record in the sorted file?


Thanks
 
S

Stephan Wilms

Hi,

Well, your question does not really relate to the ANSI-C language as
such, so its not an easy one to answer within the context of this
group. Moreover it really is very unspecific. What you are asking for
is advice on database design and/or data representation within an
application.

Here is some general advice. There are methods for fast and direct
access to components of database tables. The fastest two are:

1) direct indexed access, when your "key ID" corresponds to the
positional index of the record

2) hash table access, where the index to access a record is calculated
from your "key ID"

Additionally the search speed within sorted lists can be improved
drastically by using a binary search algorithm. For the sake of
topicallity allow me to mention that all the things I recommended can
be coded in ANSI-C :)
 
R

Robert Stankowic

kids said:
Hi all,
i have 2 files, 1 file that store 1000 records of name entries and
it's key ID. With the sorting function all the records have been sorted and
its correspond key id was store in a sorted file. If 1 of record has been
deleted, i have to keep looping the sorted file to find the deleted record
Key Id and delete it. Any better way instead of using for loop to find the
record in the sorted file?


Thanks

If possible, read the sorted file into memory and use bsearch()
(If I don't misunderstand you, the sorted file contains just the keys, and
1000 keys should easily fit in memory)

Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top