Is TMap documented at ALL?
BlitzMax Forums/BlitzMax Beginners Area/Is TMap documented at ALL?
| ||
Seriously, I'm going through the docs and I can't find anything. Now without a proper search and with everything split into about four parts, it's possible that I've missed something, but I've found precisely nothing. I tried a forum search too, but it throws up a huge list of threads none of which appear to be directly on the subject of a proper explanation. Are there any docs at all for this? |
| ||
No But it is not hard to get in: TMap is a key based data structure to store data (internally a non balanced binary tree). To put something in, use .Insert(key:object, value:object) To get something use: ValueForKey:object(key) if you want to iterate through them with eachin: eachin tmap.values() or eachin tmap.keys() That is what you normally will need. everything else can be found in the module sources. |
| ||
TMap is a key based data structure to store data (internally a non balanced binary tree). Well perhaps if I knew what a key-based data structure was, it wouldn't be hard to get into. I get the functions and methods, it's more the concept I'm struggling with. I know that a list is less than ideal for what I'm doing, but without proper documentation, I have no idea if TMap would be better. Am I right in thinking that the Key might often be a string, and that the string is used to look up entries in a map? Kinda like an index in a book? What else might I use if not a string? Any UDT? Could it, in fact, be used to resolve my other problem posted in this forum regarding "instanced" types? IE: Post the key as the image object and the value as the new image object, when it is replaced. Then simply tell all game objects to look up the value attached to the key they already have and replace the image ( currently the key ) with the value ( the new image ) ? everything else can be found in the module sources. Yes, I'm going through the module source now. However, I feel obliged to mention that reading through source and figuring it out for yourself is fine when you're using a freeware product, but a bit much when you've bought a commercial product. And one that's been out for a pretty long time now. |
| ||
You might use any object type that is comparable as key as they are inserted and searched basing on that. So in the end, any non numeric could be used :-) And yes it could be used to resolve that problem. But it would need testing to see if it is fast enough or if a simple list within a new image type would be a better idea. (the list then would hold all instances using this image) I'm not sure that TMap was meant to be used from outside ... It was needed for some internal things ... So it just got not documented. As I'm using Hotdocs I don't mind much if it is documented or not as the OO part is not that documented anyway. |
| ||
If it helps, BlitzWiki has a commented example: http://www.blitzwiki.org/index.php/Map And, no, TMap doesn't seem to be in the docs at all (not that searching assari's .chm version of the 1.20 help could find). |
| ||
Thanks for the information, Dreamora, and the link, Wendell. I understand the basics now, but I don't quite get the TEnumer, TNodeEnum, TKeyEnum and TValueEnum types. I understand Wave's example just fine, but it's too basic and only covers the stuff I figured out on my own. GMan's example covers a lot more, and I see what he's doing, but I don't quite see the purpose of the enum stuff. But I think I understand enough to use these to fix my graphics reloading problems, and it will be completely seamless once I abstract the load and unload functions, which is great. |
| ||
Enum Types are types that you can generate for any of your own classes that shall be able to use "eachin" to enumerate. TValueEnum for example is used if you do eachin with tmap.values(). The same goes for the others. I think that is even somewhere documented, how you can add eachin support to your own classes. But good that it helps you :-) If I find time I might even replace the bintree under it with an AVL tree which would greatly speed up the average time to add / remove and find stuff ... at the moment you get a linked list in worst case (adding the smallest element and then adding the next larger). Naturally I would provide the community with that fix in hope to get it into the official mods at a later date :-) |
| ||
Enum Types are types that you can generate for any of your own classes that shall be able to use "eachin" to enumerate. Except technically, they iterate rather than enumerate (get numbers assigned to them).You might want to know that a TMap is a Set (that is each key must be unique) and if you try to insert a value with the same key as an exsisting value, it will replace the old one with the new one, rather than throw an exception (as it should IMHO). |
| ||
Enum Types are types that you can generate for any of your own classes that shall be able to use "eachin" to enumerate. TValueEnum for example is used if you do eachin with tmap.values(). The same goes for the others. Oh, I see. That makes perfect sense. Much like iEnumerable in C#. I think that is even somewhere documented, how you can add eachin support to your own classes. I haven't found it but considering how badly organized the docs are, that's entirely possible. That actually sounds very useful, but I expect I can figure it out now that I know it's possible and have examples. You might want to know that a TMap is a Set (that is each key must be unique) and if you try to insert a value with the same key as an exsisting value, it will replace the old one with the new one, rather than throw an exception (as it should IMHO). Heh, that's lucky. I had - for some reason - just assumed that this would be the case, and my code was relying on it. At least I won't have to go back and add in a little code to remove nodes before adding new ones. |
| ||
I haven't found it but considering how badly organized the docs are, that's entirely possible. Come on, give them a break! It's under: Language -> Collections. |