You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Associative Arrays
06-05-2017, 04:49 PM
Post: #11
 (Print Post)
RE: Associative Arrays
im going to attempt the poor man's approach (something i can grasp)
i don't even know what a dictionary or a hash table is don't tell me
i want to see if i can figure this out
you guys are posting faster then me and im falling behind cant keep up
Find all posts by this user
Like Post
06-05-2017, 05:48 PM (This post was last modified: 06-05-2017 06:17 PM by Waltersmind.)
Post: #12
 (Print Post)
RE: Associative Arrays
sorry fig but looks to me that you mix up some things
walter is closer ...Wink

associative array is not same thing as - hash table | map | dictionary

here is example in Oxygen Basic ..Charles show me that hash table is not trivial
task at all,in his example you may see assembly code for hashing function
using XOR and ROL...rotate left function

Code Snippet: [Select]
function hashcode(string s) as long
===================================
if not s then return 0
byte b at (strptr s)
sys  e=len s
sys  a=e*256
sys  i
for i=1 to e
 a = a xor 0x3a575a73 xor b
 rol a,18
 @b++
next
return a
end function


function hashcodeA(string s) as long
====================================
 xor eax,eax
 mov edx, [s]     ' name pointer
 mov ecx, [edx-4] ' length
 (
 cmp ecx,0
 jnz exit
 return 0 'EMPTY WORD WILL TRIGGER HASHCODE ERROR LATER
 
 mov ah,  cl      ' assume max length 255
 (
   xor al,  [edx]
   xor eax,0x3a575a73
   rol eax,18
   inc edx
   dec ecx
   jnz repeat
 
 return eax
 '
 end function

 n="A" : print hex(Hashcode(n)) + "    " + hex(HashcodeA(n))
 n="Maxmillian" : print hex(Hashcode(n)) + "    " + hex(HashcodeA(n))

associative array is array where index is UDT -pointered
and here is example in O2 where I modify original code
which is OOP (classes/methods) but can be created in procedural way using one main function with
sub functions, here is very clear how OOP is excellent in o2..i mean easy to FIGure what is what:

Code Snippet: [Select]
Class AssociativeArray  
'=====================  
 
 bstring s,c1,c2,c3
 sys     max  
 '
 method find(string k) as sys  
 sys i=instr(s, c1+k+c2)
 if i>max then i=0
 return i
 end method  
 '
 method dat(string k) as string
 'GET  
 sys i=find k
 if i then
   i=instr i,s,c2
   sys j=instr(i,s,c3)
   if j then return mid s,i+1,j-i-1
 end if
 end method  
 '
 method dat(string k, d) as sys
 'PUT
 sys i
 if max=0 then
   'SET FIELD MARKERS
   c1=chr(1) : c2=chr(2) : c3=chr(3)
 else
   i=find k
 end if
 if i=0 then
   'APPEND
   sys m=max+len(k)+len(d)+3
   if m>len s then
     s+=nuls 0x1000+m-max 'stretch at least 4k
   end if
   mid s,max+1,c1+k+c2+d+c3
   i=max
   max=m
 else
   'REPLACE
   i+=len(k)+2
   sys j=instr(i,s,c3)
   if j then
     'INSERT DATA
     s=left(s,i-1)+d+c3+mid(s,j+1)
     max=len s
   end if
 end if  
 return i  
 end method

 method clear()
 s="" : c1="" : c2="" : c3="" : max=0
 end method

 method fill(sys n,...)
 sys i
 indexbase 0
 bstring w at @param
 n+=n
 for i=1 to n step 2
   dat w(i),w(i+1)
 next
 end method
 
end class  
 
 
'====  
'TEST  
'====  

'new
AssociativeArray arr01
int n
string cr=chr(13)
string ch="",value,buff=""
'A-Z
'n=65
For n=65 to 90
 value = str(n)
 ch    = chr(n)
   arr01.fill 1,ch,value
   buff = buff + ch + " " + arr01.dat(ch) + cr  
Next n
'asci map from 65-90
print buff


but OWEN
as Walter said you dont need to use what someone else think that you must
For example in Aurelbasic i use Linked List to store variable values
In Ruben i use just ordinary arrays.


Attached File(s) Image(s)
   

basicPro forum:
http://basicpro.mipropia.com/smf/index.php
EU Radioboard forum:
http://euradioboard.createmybb3.com/index.php
AurelSoft main site:
http://aurelsoft.ucoz.com
Find all posts by this user
Like Post
06-05-2017, 05:52 PM
Post: #13
 (Print Post)
RE: Associative Arrays
,,hmm why the heck is now text striked..ohhh
sorry people about that i cannot remove striked lines Sad

basicPro forum:
http://basicpro.mipropia.com/smf/index.php
EU Radioboard forum:
http://euradioboard.createmybb3.com/index.php
AurelSoft main site:
http://aurelsoft.ucoz.com
Find all posts by this user
Like Post
06-05-2017, 06:05 PM
Post: #14
 (Print Post)
RE: Associative Arrays
Quote:
associative array is not same thing as - hash table | map | dictionary

thats ok, we dont have to agree. i never hear people use the term anymore, only the others.

https://en.wikipedia.org/wiki/Associative_array
Quote:
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection.

so i know wikipedia is wrong sometimes. but it directly contradicts you in the first line of the article.

also on the fb forum, vdecampo says:

Quote:
An associative array is an array of (key, value) pairs. So you could reference a name with a phone number...ie:
array("301-555-1212", "Vincent")

name = array("301-555-1212")

so here is a hash table ("dictionary") from your "favourite" language:

arr={"301-555-1212":"Vincent"}
name = arr[ "301-555-1212" ]

though i think he meant: arr={"Vincent":"301-555-1212"}

both work. his example does the lookup by phone number though, usually you do the lookup by person.

in every context i know of, they are the same thing. walt may indeed be closer, but your post isnt helping me (personally) figure out whats what here. all the sources ive checked so far say im right. if you have other sources let me know.

and again, we dont have to agree. we can be of two opinions about this, probably, until someone shows me new info.
Find all posts by this user
Like Post
06-05-2017, 06:35 PM
Post: #15
 (Print Post)
RE: Associative Arrays
fig
in very simple words
hash table is unindexed xored array of pointers
better to say string pointers
bases on key-value pair
myhash ("key_1",value_1)

associative array is as the name says
first argument is association to index

so internally are different...look in my examples
from oxygen examples i learn that hash table is very fast
when associative array is slower in execution.

basicPro forum:
http://basicpro.mipropia.com/smf/index.php
EU Radioboard forum:
http://euradioboard.createmybb3.com/index.php
AurelSoft main site:
http://aurelsoft.ucoz.com
Find all posts by this user
Like Post
06-05-2017, 06:40 PM (This post was last modified: 06-05-2017 06:48 PM by figosdev.)
Post: #16
 (Print Post)
RE: Associative Arrays
Quote:
associative array is as the name says
first argument is association to index

the "hash tables" i use do that too. natively in older versions, and through list conversion in newer ones:

print dictionary.keys()[0] #is it possible we are quibbling here?

or that a hash table is a type of associative array? any source i can find seems to imply it is an example of one at least. nothing walt said seems to contradict that either. and yes, hash tables are fast.

edit: this seems to partially support what youre saying-- and *also* that a hash table is a type of what youre talking about:

Quote:
Dictionary is an Abstract Data Type. A Dictionary can refers to any data structures that provides a key to value mapping.

A Hash Table, on the other hand, is a Concrete Data Structure. A Hash Table uses a hashing function to convert keys to indices of an internal array and has a collision resolution.
https://stackoverflow.com/questions/1869...onary-in-c
Find all posts by this user
Like Post
06-06-2017, 12:23 PM
Post: #17
 (Print Post)
RE: Associative Arrays
Thanks every body.
Yes, I agree, if it's my own language, I can make it how I like....
Also I agree with those who say that associative array keys must be unique.

Even though freebasic does not include a data type for associative arrays, it is something I can implement. The speed of my poor man's implementation is not something I am addressing.
My technique will be crude and wasteful in every way possible I'm sure. Efficiency is for tomorrow .
Find all posts by this user
Like Post
06-06-2017, 12:52 PM
Post: #18
 (Print Post)
RE: Associative Arrays
theres certainly nothing wrong with what youre doing owen, i think its going to be cool.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Dakapo
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Rotating Background
QB64 Member Project - Spiro Roses
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Othello
QB64 Member Project - Rubix's Magic
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Quarto
QB64 Member Project - Blokus
QB64 Member Project - Sabotage
QB64 Member Project - Splatter
QB64 Member Project - Line Thickness
QB64 Member Project - Score 4
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Algeria Weather
QB64 Member Project - Touche
QB64 Member Project - Overboard
QB64 Member Project - Swirl
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Input
QB64 Member Project - Basic Dithering
QB64 Member Project - Inside Moves
QB64 Member Project - Exit
QB64 Member Project - Kings Court
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Bowditch curve
QB64 Member Project - Isolation
QB64 Member Project - 9 Board
QB64 Member Project - Foursight
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Qubic
QB64 Member Project - Amazon
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Dreamy Clock
QB64 Member Project - Color Triangles
QB64 Member Project - Pivot version two
QB64 Member Project - Connect Four
QB64 Member Project - ARB Checkers
QB64 Member Project - Color Rotating Text
QB64 Member Project - OpenGL Triangles
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Domain
QB64 Member Project - Pivet version one
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Point Blank