Page 1 of 2

Posted: Mon Nov 04, 2002 7:11 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.

Hi @ all

I want to code a little database, but I want to use LinkedLists instead of arrays. But there is one Problem for me, for eg my array looks like this:

Structure Person_struct
name.s
street.s
age.b
EndStructure

dim Person.Person_struct(100,10)

How could I rewrite this in a linked list? It would be nice to see two different structures declared in one.

Eg.:

Code: Select all

Structure Person
Name.s
Street.s
Age.b
amountofsisters.b
   structure sisters
   name.s
   street.s
   school.s
   endstructure
endstructure
I know that this is not possible but how to realize it in PB?



PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten

Posted: Mon Nov 04, 2002 8:14 pm
by BackupUser
Restored from previous forum. Originally posted by Berikco.

You can use structure in structure

Code: Select all

Structure VILLAGE  Street.s
  Number.s
  City.s
EndStructure


Structure PPL
  Name.s
  Place.VILLAGE
EndStructure


Db.PPL
Db\Place\Street="StationRoad"
Debug Db\Place\Street
Take a look at Linkedlist.pb that comes with PureBasic.

Regards,

Berikco

http://www.benny.zeb.be

Posted: Tue Nov 05, 2002 12:54 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by MrVainSCL

Hi @ all

I want to code a little database, but I want to use LinkedLists instead of arrays. But there is one Problem for me, for eg my array looks like this:

Structure Person_struct
name.s
street.s
age.b
EndStructure

dim Person.Person_struct(100,10)

How could I rewrite this in a linked list? It would be nice to see two different structures declared in one.

Eg.:

Code: Select all

Structure Person
Name.s
Street.s
Age.b
amountofsisters.b
   structure sisters
   name.s
   street.s
   school.s
   endstructure
endstructure
I know that this is not possible but how to realize it in PB?

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
To add to Berickco's fine example, try my example for multiple elements

Code: Select all

Structure home
  hstreet.s
  hnumber.s
  hcity.s
  hstate.s
  hcountry.s
  hphone.s
  hemail.s
  hmobile.s
EndStructure

Structure work
  wstreet.s
  wstreet.s
  wcity.s
  wstate.s
  wcountry.s
  wphone.s
  wemail.s
  wmobile.s
EndStructure

Structure person
  name.s
  age.s
  birthday.s
  nickname.s
  comment.s
  resting.home
  working.work
EndStructure

NewList addressbook.person()

;-------------------------------------------------
AddElement(addressbook())

addressbook()\name = "harry"
addressbook()\age = "360"
addressbook()\birthday = "Last century"
addressbook()\nickname = "Old hamster"
addressbook()\comment = "Computer geek"

addressbook()\resting\hstreet = "Down the road man"
addressbook()\working\wstreet  = "Beyond the black stump"
  
Debug addressbook()\working\wstreet

Fangles woz ear orright den?

Posted: Tue Nov 05, 2002 6:55 am
by BackupUser
Restored from previous forum. Originally posted by fweil.

Fangbeast,

This should be added to documentation I think. A good example.

Thnx

Francois Weil
14, rue Douer
F64100 Bayonne

Posted: Tue Nov 05, 2002 8:16 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by fweil

Fangbeast,

This should be added to documentation I think. A good example.

Thnx

Francois Weil
14, rue Douer
F64100 Bayonne
Thanks for the kind words but I have never used structure in structure before Berickco showed his example and I should have either commented it (like I usually do) or do exactly MrVain's example to help him.

I use Linked lists for just about everything and have for the last 9 months but all single structure and all of my apps (except LibTracker) use it for large amounts of data :):)

Fangles woz ear orright den?

Posted: Tue Nov 05, 2002 8:23 am
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Okay, possible MrVain did not explain correctly. I know his problem and its still now solved. Take a look on Fangbeast example. What to do if a person has more workplaces then one. You dont know how many this person have. So you need to add them to this person in another linked list or do I see something wrong?

The Database should look like this:

- First Element

Name: Mike
Age: 25
WorkplacesCount: 3
- First SUB Element

Workplace 1 Name : DB Cargo AG
Workplace 1 Street : Masurenallee
- Second SUB Element

Workplace 2 Name : blablablabla
....

- NEXT ELEMENT

......


That is MrVain and my Problem. :)

Mike



Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Tue Nov 05, 2002 10:46 am
by BackupUser
Restored from previous forum. Originally posted by Sweenie.

Well, I suppose you have to "think" like a database in this case.

One main list for the person information,
and one separate list containing all workplaces.
Then you have to "tie" them together by using a unique ID.(Key)

To fetch all workplaces for a certain person you will have to scan through the workplace list
by using the key.

Structure person
name.s
age.s
birthday.s
nickname.s
comment.s
workID.s <--- Keyfield
EndStructure

Structure work
workID.s <--- Keyfield
wstreet.s
wstreet.s
wcity.s
wstate.s
wcountry.s
wphone.s
wemail.s
wmobile.s
EndStructure

You could also use a combination of fields to make a key.
As long as you make sure that the combination never occurs more than once in the person list.

A person's lastname is a bad key, because there might be another user in the list with the same lastname and then the key wouldn't be unique.

//Sweenie

Posted: Tue Nov 05, 2002 10:52 am
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Thats the way I suggested but's a lot of work. :-(
But seems that this is the only way so I need to use this one.

Thanks to all for their answers and help!

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Tue Nov 05, 2002 11:02 am
by BackupUser
Restored from previous forum. Originally posted by Sweenie.

Why not using an Access database?
Then all the hard work will be handled by the Access-db.

//Sweenie

Posted: Tue Nov 05, 2002 11:15 am
by BackupUser
Restored from previous forum. Originally posted by tranquil.

We are coding a FileSharing Application the eDonkey-Net and others. Atm I'm using Arrays to manage the sources for files, uploadqueue, connections etc. But this are strongly limited by the dimension and a huge amount of memory needed by the Dim at the beginning of my code.

Anyway it is easyier to use LinkedLists couse I do not need to move thousendend Bytes in an array if one Source is Death and ready to remove from list. In an Array I have to move all the behind sources one array to front by a For...Next loop, in a linked list its just one command that does the same.

So I think a Database of Access is not the best way in this case, maybe in others. Thanks for that Hint.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Tue Nov 05, 2002 11:18 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by tranquil

Thats the way I suggested but's a lot of work. :-(
But seems that this is the only way so I need to use this one.

Thanks to all for their answers and help!

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
Mike, my example will still work and doesn't need unique ID's. As you might know, an element in a linked list only takes as much memory as the data in it. So what I would do is.....

Add a new item to the workplace and home structures called placeID and generate a crc from the person's full name and something else when the record is filled. Do not bother to display the placeid, you can search on it or the person's name for records.

procedure:

1. Add a new element, populate all the fields, including the workplace.

2. A part of your form, the sub form where you enter work details, will ask you if you have finished entering workplaces. Each time you add a new workplace, a whole new record is generated. Remember, this doesn't matter as it will only take as much memory for the element as there is data in it (unlike arrays). Linked lists are memory efficient.

3. When you search for a person, display only those records that match the person. When you search for workplaces for a person, search the person or unique placeID for whom the workplaces exist but display only the workplaces for that person, just hide the data you don't want to display. Simple.

All the data is still in one linked list!!!

Fangles woz ear orright den?

Posted: Tue Nov 05, 2002 11:34 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.

why not use pointers in your structure to another structure, something like this:

Code: Select all

structure StreetType
  name.s
  nr.w
  *parent
  *child
endstructure

structure DataBaseType
  name.s
  etc.l
  *street
endstructure

newlist streets.StreetType()
newlist database.DataBaseType()

; ok now add an entry
addelement(database())
addelement(streets())
database()\name = "Vain"
database()\street = @streets()
*ptr.StreetType = @streets()
street()\name = "somewhere"
; he lives on another address too so..
addelement(street())
street()\name = "somewhere else"
*ptr\child = @street()

; now you can access this structure like this
resetlist(database())
while nextelement(database())
  *ptr = database()\*street
  if *ptr ; we have a street
    debug *ptr\name
    while *ptr\child
      *ptr = *ptr\child
      debug *ptr\name
    wend
  endif
wend
well something like that, i haven't tested because i'm at work at the moment, but the logic should be ok...

Posted: Tue Nov 05, 2002 11:36 am
by BackupUser
Restored from previous forum. Originally posted by tranquil.

@Fangbeast

Its likly that what Sweenie said before. He uses an unique ID and you are using a CRC in one list. I think I will prefere the uniqueID System in two linked lists to get a better overview.

Cheers
Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Tue Nov 05, 2002 4:22 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.

uiii.... wohttp://www... so many tips in this small time when i was at work! Many thanks for all the tips and helps! :wink:


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten

Posted: Wed Nov 06, 2002 12:37 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by tranquil

@Fangbeast

Its likly that what Sweenie said before. He uses an unique ID and you are using a CRC in one list. I think I will prefere the uniqueID System in two linked lists to get a better overview.

Cheers
Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
Fair enough.

The only reason I use one linked list instead of two is because I don't have to sacrifice speed by looping through two lists in memory trying to find a match. I only have one list and one set of unique ID's per person so I loop through only one list and my elements are always in line because I do a data sort before I save the data in case I have come back later and added another address for a person and the data is no longer sorted..

More than a million ways to do anything :):):) (All of them fun)


Fangles woz ear orright den?