Numeric Maps

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Numeric Maps

Post by mk-soft »

Hello Fred,

Please publish the internal existing Numeric Map functions as purebasic functions.
NewNumericMap, etc

Thanks :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Numeric Maps

Post by jacdelad »

Was requested numerous times and I totally give it a +1!
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Numeric Maps

Post by skywalk »

Is there a significant speed improvement with map access using integer keys?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Numeric Maps

Post by ChrisR »

+1, It would be really nice to have it natively to avoid AddMapElement(Map(), Str(Key)), FindMapElement(Map(), Str(Key))
and a second +1 if the function is already there :!:
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Numeric Maps

Post by Tenaja »

Time flies; I asked about this ten years ago. There are some solutions in this thread:
https://www.purebasic.fr/english/viewto ... 38#p440238
Last edited by Tenaja on Sat Jan 20, 2024 10:36 pm, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Numeric Maps

Post by mk-soft »

ChrisR wrote: Sat Jan 20, 2024 6:32 pm +1, It would be really nice to have it natively to avoid AddMapElement(Map(), Str(Key)), FindMapElement(Map(), Str(Key))
and a second +1 if the function is already there :!:
Would have to be nicely implemented by Fred :wink:
Link: https://www.purebasic.fr/english/viewtopic.php?t=74214
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Numeric Maps

Post by ChrisR »

Thanks for the link :)
idle wrote: Sun Dec 15, 2019 10:22 pm
Fred wrote:Messing with internal code isn't really a trick and tips as it can be broken anytime. If it's not released, it's because it's ready for :)
Note to self, don't unwrap Fred's xmas presents :lol:
For Christmas it's too late but we have until January 31st to wish to all a happy new year :wink:
or else it's good to keep dreaming that one day it will arrive 8)
Quin
Addict
Addict
Posts: 1131
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Numeric Maps

Post by Quin »

+1. This would save me from calling Str() in so many places and definitely improve performance.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Numeric Maps

Post by Caronte3D »

+1 For sure
User avatar
idle
Always Here
Always Here
Posts: 5840
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Numeric Maps

Post by idle »

ChrisR wrote: Sat Jan 20, 2024 8:27 pm Thanks for the link :)
idle wrote: Sun Dec 15, 2019 10:22 pm
Fred wrote:Messing with internal code isn't really a trick and tips as it can be broken anytime. If it's not released, it's because it's ready for :)
Note to self, don't unwrap Fred's xmas presents :lol:
For Christmas it's too late but we have until January 31st to wish to all a happy new year :wink:
or else it's good to keep dreaming that one day it will arrive 8)
Use Squint3 it's a bit faster than a map, grows dynamically and is faster to exit if a key doesn't exist
https://www.purebasic.fr/english/viewtopic.php?t=79453
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Numeric Maps

Post by ChrisR »

idle wrote: Sat Jan 20, 2024 9:47 pm Use Squint3 it's a bit faster than a map, grows dynamically and is faster to exit if a key doesn't exist
https://www.purebasic.fr/english/viewtopic.php?t=79453
Promise the next time I need a map with a numeric or alphanumeric key and a bit of performance, I'll try Squint3 :wink:
I had already seen your great Module (like other great code from you. Looking at them makes me feel like a noob) but I haven't used it yet.
Code with embedded C or ASM has always scared me a bit, because I don't know anything about them, I don't know what's being done and I can't control the code if I need to. Even if I'm confident
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: Numeric Maps

Post by AZJIO »

The key is not just a string, but the binary data of the string. Perhaps another good way is to pass a pointer to a string, then it would be possible to add another parameter - the length of the string StringByteLength(). If the length is not specified, then it is determined by 00, and if a pointer to a number is used, then SizeOf can be specified. In any case, the data will no longer have a special type.
User avatar
idle
Always Here
Always Here
Posts: 5840
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Numeric Maps

Post by idle »

ChrisR wrote: Sat Jan 20, 2024 10:30 pm
idle wrote: Sat Jan 20, 2024 9:47 pm Use Squint3 it's a bit faster than a map, grows dynamically and is faster to exit if a key doesn't exist
https://www.purebasic.fr/english/viewtopic.php?t=79453
Promise the next time I need a map with a numeric or alphanumeric key and a bit of performance, I'll try Squint3 :wink:
I had already seen your great Module (like other great code from you. Looking at them makes me feel like a noob) but I haven't used it yet.
Code with embedded C or ASM has always scared me a bit, because I don't know anything about them, I don't know what's being done and I can't control the code if I need to. Even if I'm confident
truth be told I can barely control the code and I wrote it. :lol:
AZJIO wrote: Sat Jan 20, 2024 10:49 pm The key is not just a string, but the binary data of the string. Perhaps another good way is to pass a pointer to a string, then it would be possible to add another parameter - the length of the string StringByteLength(). If the length is not specified, then it is determined by 00, and if a pointer to a number is used, then SizeOf can be specified. In any case, the data will no longer have a special type.
squints Trie functions can be string keys or binary keys using the binary functions (but you don't mix binary and string keys in same trie)
string keys accepted are unicode(UCS2), utf8 or ascii null terminated strings (all keys are mapped to utf8 to save space)
keys are sorted on input into the Trie so you can query them by prefix, to get a sorted output in a the callback

binary keys can be anything you want up to #SQUINT_MAX_KEY = 1024 just set the size and a value, they are currently only on the root and shouldn't be used together with strings or numeric keys in the same Trie.

The map function is numeric or binary and is numerically sorted
it accepts integer keys up to sizeof(integer) and a value
or a binary key up to #SQUINT_MAX_KEY = 1024 when you set the hash flag, the binary key is then hashed
it behaves a bit like a HAT (a hash collision could be possible but very unlikely)
don't mix numeric and binary hashed keys together if you want to dump the trie as you won't be able to tell what it is

When I say strings and integer keys can both be used together in the same trie, it's only valid for numbers up to 60 bits because the numeric keys are on the roots child[0] and strings wont share that root. but you can just create another trie
an empty trie only takes up 1328 bytes which can be reduced to 304 bytes when I get around to fixing it.

maybe fred will put us out of the misery and implement the numeric map.
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: Numeric Maps

Post by moricode »

skywalk wrote: Sat Jan 20, 2024 5:33 pm Is there a significant speed improvement with map access using integer keys?
definitely faster and less conflict as integer key doesn't need to hash at all , it just need to divide the slot number and store in table only .

example :
myintmap(12345) = 9899

bucket slot size = 512
so the key = 12345

table position = 12345/512 =24 (truncated )
store the value 9899 in table position 24

conflict only if another ==> key/512 = 24 than you need chaining in table for the double entry value

over all , it is more efficient and fast , less conflict .

make one for yourself for fun :)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Numeric Maps

Post by Fred »

It's not published because I want a seemless integration (not adding AddNumericMapElement() for example but still use AddMapElement() with a numeric param) but it needs some compiler tweaks.
Post Reply