flat assembler
Message board for the users of flat assembler.
Index
> Main > Advice needed: data structures |
Author |
|
JohnFound 03 May 2012, 06:52
There are different approaches to the trees.
At first, you can use field ".ptrChildren" in your data record, that to contain pointer to array with the children records. The second approach is that the tree can be represented by simple linear array. You only need some field to contain the level information. In your case the elements of the array will have: Parent1: .level = 1 Child1: .level = 2 Definition: .level = 3 Log: .level = 4 Random stuff: .level = 5 Child2: .level = 2 ParentN: .level = 1 |
|||
03 May 2012, 06:52 |
|
typedef 03 May 2012, 07:54
you could do:
+Node | |__[x] data_size (omit if fixed size) | |__[x] data | |--+ Child (location = Parent's data.size) |
|||
03 May 2012, 07:54 |
|
typedef 03 May 2012, 07:58
Using hash: (random locations, MR Big-O will complain)
Node --header-- .hash .data_size (again, omit if fixed size) .parent (by hash) .child --end header-- .data when reading you'd read the header first then read .data_size bytes to advance. |
|||
03 May 2012, 07:58 |
|
bzdashek 03 May 2012, 08:30
Thanks, JohnFound!
About the second approach, how do children connect to parents? Also, is there a best method to find a record in a tree without having to scan through the whole tree, if using the first approach, where parent record contains a pointer to the array of child records? UPD: Thanks, typedef! I'll try to implement it. Maybe it's a good idea to keep a parallel lookup structure containing (hash,address) values? |
|||
03 May 2012, 08:30 |
|
typedef 03 May 2012, 09:01
you can also use the indexed "Natural Array mapping". Binary Tree Approach
Node { index sizeof_data data } the first record would have to be unused with index 0 Parent location = index/2 left child = 2index + 1 right child = 2index but then again it'll depend on the way you'll save the data to the file since that will be your sorting/mapping time. Also windows controls provide LPARAM pointer. With this pointer you can use to store your items. Actually you need not to sort them you just traverse the TreeView and filling the structure then save to file. Quite easy |
|||
03 May 2012, 09:01 |
|
bzdashek 14 May 2012, 20:12
I managed to build the tree using SysTreeView32 and the following structure:
Code: struct SIEBNSENTRY ;size= 32 itemHash dd ? ;4 peggeHash512 hash itemId dd ? ;4 itemId in treeContol parAddr dd ? ;4 keyName dd ? ;4 the address of the key name in keyData storage (keyData dd ? - should be dynamically alocated) keyLength dd ? ;4 length of the key name in keyData storage kPersistence db ? ;1 kType db ? ;1 kValue dd ? ;4 if "string" - pointer to value, else - value itself kLen dw ? ;2 Value length * 2 reserved dd ? ;4 ends Where: itemHash - is the hash of the string, i.e. 'enterprise'; itemId - itemID returned by AddItemin the SysTreeView32 parAddr - parent item index in the array ... program-specific fields ... reserved - 32 byte padding Then I count the number of items to be added, i.e. 65000, then allocate 65000*32+4 bytes of memory. Additional 4 bytes are placed at the start of the array, and stores the number of items currently stored in this array. The search starts comparing at the last item (having maximum index), then goes to the parent record,each time comparing hashes, until it hits the first item in the chain (the root of the tree). If item not found in array, it's being added to the end of array, and parAddr is updated with the index of the parent record. |
|||
14 May 2012, 20:12 |
|
shutdownall 15 May 2012, 11:51
This is a bit similar to XML structures.
There are many tools for handling XML. Even every browser can display. So it would maybe spare time of development to use XML I think. |
|||
15 May 2012, 11:51 |
|
bzdashek 15 May 2012, 12:59
shutdownall wrote: This is a bit similar to XML structures. Unfortunately, these files are not something I invented, but I do have to deal with them - they are part on Siebel CRM system - they contain description of every component in the system, + log levels, etc. When migrating the configuration from one server to another - it's really painful to go through all keys and fix them manually (changing server names, enterprise name, number of multiservers etc.), so that would be a tool with find/replace features, automatic key length maintaining, and checksum fixer. |
|||
15 May 2012, 12:59 |
|
typedef 15 May 2012, 19:35
If time is a choke, just do it in JAVA or C++ and get over it with.
|
|||
15 May 2012, 19:35 |
|
bzdashek 15 May 2012, 20:49
typedef wrote: If time is a choke, just do it in JAVA or C++ and get over it with. Fortunately, it is just an ad-hoc task to make mine and my colleagues life easier |
|||
15 May 2012, 20:49 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.