Jump to content

Recreate hierachy structure from flat structure in array


Recommended Posts

Hi there,

I am using SQLite to extract data from a database with one of the tables storing a "flat" file/folder structure, containing around 10000 entries.

The ParentId for the root level is kown. Due the fact the both IDs are GUIDs the data in the array is chaotic.

COLUM ParentId | COLUMN ChildName | COLUMN ChildId | COLUMN Type
ParentId_01    | ChildName_01     | ChildId_01     | File
ParentId_01    | ChildName_02     | ChildId_02     | Folder
ParentId_01    | ChildName_02     | ChildId_02     | File
...            |                  |                | 
ParentId_nn    | ChildName_nn     | ChildId_nn     | Folder

I want to extract/create the hierachy structure and I am looking for a good aproach.

My current idea would be a recursive function

  • Call the function with the Id for the root level
  • loop through the array searching for the matching GUID
    • if found and type is file, print data
    • if found and type is folder, call function again

Is there a better/possible faster approach (maybe even utilizing SQLite for this)?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...