Raised This Month: $32 Target: $400
 8% 

"Linked list"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-03-2014 , 06:27   "Linked list"
Reply With Quote #1

Ciao,

what do you think about "linked list" made via dynamic array of datapacks (every cell of array contains handle to datapack)?

Is that a good idea? I know about array of enums, but that is not dynamic..

And if I make some stocks for that solution it would be an awesome thing I guess.
KissLick is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 01-03-2014 , 07:20   Re: "Linked list"
Reply With Quote #2

Probably, there is a better way to do what you want to do.
But you can use adt array for that. Or even adt stack or global databack whichever fits you better.
xf117 is offline
Send a message via ICQ to xf117
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-03-2014 , 09:29   Re: "Linked list"
Reply With Quote #3

I meant somthing like this
PHP Code:
new Handle:gh_LinkedList INVALID_HANDLE// global variable

// Create dyn. array
gh_LinkedList CreateArray();

.
.
.

// Create and push datapacks
PushListValuesgh_LinkedList"ciao"147.35 ); // index 0
PushListValuesgh_LinkedList"hallo"3584.4 ); // index 1

.
.
.

// Get values
new String:name64 ];
new 
age;
new 
Float:height;
GetListValuesgh_LinkedList0nameageheight ); // get values from datapack on index 0
GetListValuesgh_LinkedList1nameageheight ); // get values from datapack on index 1 
and stocks
PHP Code:
// Stock for pushing datapacks
stock PushListValuesHandle:list, const String:arg164 ], arg2Float:arg3 )
{
    new 
Handle:pack CreateDataPack();
    
WritePackStringpackarg1 );
    
WritePackCellpackarg2 );
    
WritePackFloatpackarg3 );
    
    return 
PushArrayCell( list, _:pack );
}

// Stock for getting datapack values
stock GetListValuesHandle:list, index, const String:value164 ], value2Float:value3 )
{
    new 
Handle:pack Handle:GetArrayCell( list, index );
    
    
ResetPackpack );
    
ReadPackStringpackvalue164 );
    
value2 ReadPackCellpack );
    
value3 ReadPackFloatpack );


Last edited by KissLick; 01-03-2014 at 09:42.
KissLick is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-03-2014 , 18:19   Re: "Linked list"
Reply With Quote #4

Linklists are cancer
Iono why they even teach them in programming classes.
Just like data structures theory.

Unless it is for a very specific application that requires re-use of the handles for convenient storage and lookup, it's a complete waste, which almost always is the case.
They are also really hard to iterate through.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-04-2014 , 05:14   Re: "Linked list"
Reply With Quote #5

Have you ever though about array of enum of adt array

A similar solution (that i've just posted for someone else) may interest you:

https://forums.alliedmods.net/showpo...7&postcount=17
https://forums.alliedmods.net/showpo...9&postcount=20

Last edited by Mathias.; 01-04-2014 at 05:16.
Mathias. is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 01-04-2014 , 06:37   Re: "Linked list"
Reply With Quote #6

Quote:
Originally Posted by friagram View Post
Linklists are cancer
Iono why they even teach them in programming classes.
Just like data structures theory.

Unless it is for a very specific application that requires re-use of the handles for convenient storage and lookup, it's a complete waste, which almost always is the case.
They are also really hard to iterate through.
what the.... linked lists are wildly used everywhere. in windows kernel too. its the best way to store dynamically allocated variables... linked lists are far superior than reallocating a huge array just to add a single element. also, iterating through a linked list is jsut a few lines:

Code:
LinkedList * element = my_linked_list;
while(element)
{
   ...
   element= element->next;
}
also, what do you mean by convenient lookups? o.O linked lists are not key-value stores... i think you are talking about trees... but then again, tries and binary search trees are efficient, fast and used by every single database server
__________________
Taking private C++/PHP/SourcePawn requests, PM me.

Last edited by Zephyrus; 01-04-2014 at 06:51.
Zephyrus is offline
napalm00
Veteran Member
Join Date: Jun 2011
Location: Italy, sadly
Old 01-04-2014 , 18:00   Re: "Linked list"
Reply With Quote #7

In addition to what Zephyrus said, depending on the implementation linked lists can be iterated in both directions (right->left or left->right).
__________________
napalm00 is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-04-2014 , 19:05   Re: "Linked list"
Reply With Quote #8

Perhaps sl, but linked lists in c are much different than sourcepawn implementations...
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-04-2014 , 20:32   Re: "Linked list"
Reply With Quote #9

Quote:
Originally Posted by napalm00 View Post
In addition to what Zephyrus said, depending on the implementation linked lists can be iterated in both directions (right->left or left->right).
That would be the difference between a Linked List and a Doubly Linked List.

Linked lists have their uses, but ease of lookups isn't one of them... from any position in a linked list, you only know what the next element is (and previous element for doubly linked lists). In other words, you're not likely to run into too many cases where they're actually useful for SourcePawn.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-04-2014 at 20:34.
Powerlord is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 01-05-2014 , 17:20   Re: "Linked list"
Reply With Quote #10

Thx guys for your opinions! You helped me ;-)
KissLick is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode