RE: [Dev-C++] Re: Dev-cpp-users digest, Vol 1 #610 - 10 msgs
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-02-13 00:07:45
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Flavio de Souza
> Sent: Tuesday, February 12, 2002 11:20 PM
> To: dev...@li...
> Subject: [Dev-C++] Re: Dev-cpp-users digest, Vol 1 #610 - 10 msgs
>
>
> Thanks everybody for the valuable help!
>
> Thanks Devin, Ioannis, Bob, etc
>
> Ioannis, to answer your question:
>
> I will use C++ ( I am trying as much as possible to program in C++)
>
> Basically the type of search I will use is the following:
>
> Let's say I have many "NOTES" with several lines.
>
> _______My Notes Database_____________
> NOTE 1
> alsjdf aldlfa lasjf
> lakjslf
> aljsdflas
> NOTE 2
> alsjdf aldlfa lasjf
> lakjslf
> aljsdflas
> NOTE 3
> alsjdf aldlfa lasjf
> lakjslf
> aljsdflas
> NOTE 4
> alsjdf aldlfa lasjf
> lakjslf
> aljsdflas
> ----------------------------------------------------------------
>
> I want to get to the Note by using some kind of ID or maybe
> get the an address position inside the file and go directly
> to the note (just an idea, I don't know how to do that)
>
> Any comments? Ideas?
Yes, you will create a binary file (or text if you want to share it
between various versions of your program, linux e.t.c.) and you will
place in it the records in ascending order acccording to their id. There
will be a boolean variable in every record indicating if the file was
deleted.
E.g.
class record
{
unsigned long ID;
bool deleted;
// ...
public:
record(unsigned long id): erased(false), ID(id) {}
bool is_erased() { return deleted; }
void erase() { deleted=true; }
// ...
};
Every time you erase a record e.g. a you will do
a.erase();
This is called logical deletion.
At the end of your program or after every logical erasion or how you
decide to do it, you will create a temporary file, you will copy the
contents of your primary file there, and then from there you will copy
back only the records whose .is_erased() is false. This is called
physical deletion. Also in some phase (probably in the temp file) you
will sort the non-erased records according to their ID (giving new ID
numbers to make them continuous, e.g. when you have the non erased
remaining records with IDs 1, 3,4 e.t.c. you will do them 1,2,3. You
will probably do this before the copy back (before the physical
deletion) in the style:
int i=0;
go_to_begin_of_file
read record to a record variable
if (!variable.is_erased())
variable.makeid(i++);
go back one record
write record
read next record...
And then copy back to the original file without the logically erased
records
It is easy if you think on it. :)
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|