Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

stavljanje dinamickoh struktura u fajl

[es] :: C programiranje :: stavljanje dinamickoh struktura u fajl

[ Pregleda: 960 | Odgovora: 6 ]

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

vladab
Vladimir Bašanović
Beograd

Član broj: 9512
Poruke: 496
195.252.106.*



Profil

icon stavljanje dinamickoh struktura u fajl13.03.2005. u 11:25

Pravim nesto u C++ i imam binarno stablo i neke liste. Da li mogu da ubrzam podizanje svog programa tako sto cu na neki nacin smestiti na hdd te strukture i posle ih samo prebaciti u operativnu memoriju. Stablo ima oko 100.000 clanova, pa mi formiranje stabla svaki put kada startujem program deluje mnogo sporo i lose. :O)
Seven deadly sins
Seven ways to win
Seven holy paths to hell
And your trip begins

Seven downward slopes
Seven bloodied hopes
Seven are your burning fires,
Seven your desires...
13.03.2005. u 11:25 

X Files
Vladimir Stefanovic
Pozarevac

SuperModerator
Član broj: 15100
Poruke: 2768
*.nat-pool.po.sbb.co.yu.

Jabber: xfiles@elitesecurity.org
Sajt: www.antivari.com


Profil

icon Re: stavljanje dinamickoh struktura u fajl13.03.2005. u 19:05
Citat:

[...] Da li mogu da ubrzam podizanje svog programa tako sto cu
na neki nacin smestiti na hdd te strukture i posle ih samo prebaciti
u operativnu memoriju. [...]


Definitivno je moguce (i pozeljno). Nisam nikada snimao binarnu
strukturu 'stabla', ali evo ti deo koda koji radi 'slicnu' stvar za
'TListView' komponentu, cisto da 'osetis' koncept. Kod binarnog
stabla, pretpostavljam da redosled obilazenja treba da bude i
redosled pisanja/citanja, pri cemu (valja) treba da napravis i
svoje kontrolne karaktere koj ce definisati nivoe. Bas me zanima,
kako ces to resiti. Javi ;)


Code:


    bool __fastcall ReadBool(TStream *Stream)
    {
        bool Result = false;
        Stream->Read(&Result, sizeof(bool));
        return Result;
    }

    void __fastcall WriteBool(TStream *Stream, bool Value)
    {
        Stream->Write(&Value, sizeof(bool));
    }

    int __fastcall ReadInteger(TStream *Stream)
    {
        int Result = 0;
        Stream->Read(&Result, sizeof(int));
        return Result;
    }

    void __fastcall WriteInteger(TStream *Stream, int Value)
    {
        Stream->Write(&Value, sizeof(int));
    }

    AnsiString __fastcall ReadString(TStream *Stream)
    {
        int length = ReadInteger(Stream);
        if( length > 0 )
        {
            AnsiString Result;
            Result.SetLength(length);
            Stream->Read(Result.c_str(), length);
            return Result;
        }
        return "";
    }

    void __fastcall WriteString(TStream *Stream, const AnsiString &Value)
    {
        int length = Value.Length();
        WriteInteger(Stream, length);
        if( length > 0 )
            Stream->Write(Value.c_str(), length);
    }

    void __fastcall ReadStrings(TStream *Stream, TStrings *Values)
    {
        int count = ReadInteger(Stream);
        Values->BeginUpdate();
        try
        {
            Values->Clear();
            for(int x = 0; x < count; ++x)
                Values->Append(ReadString(Stream));
        }
        __finally {
            Values->EndUpdate();
        }
    }

    void __fastcall WriteStrings(TStream *Stream, TStrings *Values)
    {
        int count = Values->Count;
        WriteInteger(Stream, count);
        for(int x = 0; x < count; ++x)
            WriteString(Stream, Values->Strings[x]);
    }


    void __fastcall SaveListItems(TStream *Stream, TListItems *Items)
    {
        int count = Items->Count;
        WriteInteger(Stream, count);
        for(int x = 0; x < count; ++x)
        {
            TListItem *Item = Items->Item[x];
            WriteString(Stream, Item->Caption);
            WriteStrings(Stream, Item->SubItems);
            WriteBool(Stream, Item->Checked);
            WriteBool(Stream, Item->Cut);
            WriteInteger(Stream, Item->ImageIndex);
            // other values you are interested in ...
        }
    }

    void __fastcall LoadListItems(TStream *Stream, TListItems *Items)
    {
        int count = ReadInteger(Stream);
        Items->BeginUpdate();
        try
        {
            Items->Clear();
            for(int x = 0; x < count; ++x)
            {
                TListItem *Item = Items->Add();
                Item->Caption = ReadString(Stream);
                ReadStrings(Stream, Item->SubItems);
                Item->Checked = ReadBool(Stream);
                Item->Cut = ReadBool(Stream);
                Item->ImageIndex = ReadInteger(Stream);
                // other values you are interested in ...
            }
        }
        __finally {
            Items->EndUpdate();
        }
    }

Zatim, sve to koristis kao:

    SaveListItems(SomeTargetStream, ListView1->Items);
    //...
    LoadListItems(SomeSourceStream, ListView1->Items);



FREEWARE
Di rečnik, v1.0.058 (srp-eng/eng-srp priručni rečnik)
http://www.antivari.com
13.03.2005. u 19:05 

yooyo
Centroid / Technical director

Član broj: 4891
Poruke: 1101
*.beotel.net.



Profil

icon Re: stavljanje dinamickoh struktura u fajl13.03.2005. u 22:29
Mozda bi mogao da preradis malo organizaciju u memoriji tako sto ces sve nodove drveta drzati u nizu, a umesto pointera koristiti indekse. Snimanje i ucitavanje u tom slucaju bi bilo vrlo jednostavno i brzo.

Problem je ako u toku rada programa cesto ubacujes nodove u drvo ili ih izbacujes. U tom slucaju bi trebalo da napises neki pametan mem alokator za drvo koji bi mogao da iskoristi rupe u nizu za nove elemente. Na kraju, pre snimanja mozes da defragmentujes niz.

yooyo
13.03.2005. u 22:29 

vladab
Vladimir Bašanović
Beograd

Član broj: 9512
Poruke: 496
*.unilib.bg.ac.yu.



Profil

icon Re: stavljanje dinamickoh struktura u fajl15.03.2005. u 12:13
To sa nizom je i meni palo na pamet. Program (ocigledno) treba da sluzi za pretrazivanje gomile txt fajlova, nesto kao grep naredba, samo brze. :o) Videcu da li je to potrebno, pa cu napisati sta sam uradio. :O)
Seven deadly sins
Seven ways to win
Seven holy paths to hell
And your trip begins

Seven downward slopes
Seven bloodied hopes
Seven are your burning fires,
Seven your desires...
15.03.2005. u 12:13 

zvrba
The Lord of Chaos

Član broj: 31716
Poruke: 105
*.ifi.uio.no.



Profil

icon Re: stavljanje dinamickoh struktura u fajl15.03.2005. u 12:23
Citat:
vladab: To sa nizom je i meni palo na pamet. Program (ocigledno) treba da sluzi za pretrazivanje gomile txt fajlova, nesto kao grep naredba, samo brze. :o) Videcu da li je to potrebno, pa cu napisati sta sam uradio. :O)


Znas li da za full-text indexing postoji glimpse? http://webglimpse.net/ Pod downloads imas besplatnu command-line verziju.
15.03.2005. u 12:23 

vladab
Vladimir Bašanović
Beograd

Član broj: 9512
Poruke: 496
*.etf.bg.ac.yu.



Profil

icon Re: stavljanje dinamickoh struktura u fajl17.03.2005. u 15:57
Hvala, upravo skidam source, pa cu da vidim kako su oni to uradili.
Seven deadly sins
Seven ways to win
Seven holy paths to hell
And your trip begins

Seven downward slopes
Seven bloodied hopes
Seven are your burning fires,
Seven your desires...
17.03.2005. u 15:57 

vladab
Vladimir Bašanović
Beograd

Član broj: 9512
Poruke: 496
*.etf.bg.ac.yu.



Profil

icon Re: stavljanje dinamickoh struktura u fajl17.03.2005. u 16:28
Ovo je uradjeno pomocu hesiranja, a ja treba da uradim to pomocu stabla. Hvala u svakom slucaju. Evo pocinjem da radim preko nizova.
Seven deadly sins
Seven ways to win
Seven holy paths to hell
And your trip begins

Seven downward slopes
Seven bloodied hopes
Seven are your burning fires,
Seven your desires...
17.03.2005. u 16:28 

[es] :: C programiranje :: stavljanje dinamickoh struktura u fajl

[ Pregleda: 960 | Odgovora: 6 ]

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.