Jump to content

Maps 101: All you need to know about them!


TheDcoder
 Share

Recommended Posts

Dont take what he said for granted, as a rule of thumb there are many different kinds of thumbs.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

I am myself still discovering the usage of maps, I have stumbled upon 1 or 2 usage(s) until now... nothing worth mentioning here :P

How about being able to write Object Oriented code using nothing more than Maps and function addresses?  Roughly analogous to how Perl or Python do it?

#include <MsgBoxConstants.au3>
Local $aObjs[2] = [NewFoo(), NewBar()]
For $i = 0 To UBound($aObjs) - 1
;    Local $sMsg = ($aObjs[$i])["Output"]() ;<-- Granted, this is a bit stilted
    Local $sMsg = ($aObjs[$i].Output)() ; <-- Better, but could still be improved...
    MsgBox($MB_SYSTEMMODAL, "Test", $sMsg)
Next
Func NewFoo()
    Local $mPseudoObj[]
    $mPseudoObj["Output"] = FooOutput
    Return $mPseudoObj
EndFunc
Func FooOutput()
    Return "Foo"
EndFunc

Func NewBar()
    Local $mPseudoObj[]
    $mPseudoObj["Output"] = BarOutput
    Return $mPseudoObj
EndFunc
Func BarOutput()
    Return "Bar"
EndFunc

 

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

have to kill au3check to utilize it in @mrider fashion. 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Rule of thumb. Isn't that what your Mum holds over your Dad? Many dads appear to be happy living under that condition ... or at least they pretend to be.

It's all about Harmony and Context ... or Conditions.

You can compare everything and we do it all the time, but is it valid? That is the question.

It is valid to compare Apples and Oranges, if you are looking for the tastiest fruit of your liking.

However, in another context, the comparison may be invalid (i.e. are Oranges better than Apples).

Too many factors (some conflicting) to be able to easily come up with a penultimate answer to that last one.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

@TheDcoder - Python might be a good choice for a second (or whatever) language.  I'm not one of those that thinks that OOP is the solution to all problems, but it sure works well in some cases. :)

 

[EDIT] @‌boththose - yeah, I forgot about that.  I'm more or less just waiting until Maps are either brought into production or abandoned.  I used the Beta version for a while, but I'm not in a position to be on the leading edge of pretty much anything.  Anyway, thanks for the reminder. :)

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

@mrider - agreed I am using my scripting dictionary implementation and expanding on that until further developments.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Python might be a good choice for a second (or whatever) language.

Ahhh... python... My very first language... which I failed to learn :P.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Since it looks like some people were unsure of what I was trying to say in my benchmark, I've edited my post about the benchmark with this clarification:

CLARIFICATION: Please understand that this benchmark is NOT comparing the performance of arrays to the performance of maps.
The two serve different purposes, and if you put arrays versus maps in a fair benchmark, arrays will be faster. This is true for pretty much any programming language.
This benchmark is comparing the methods available for doing a native, dynamically-sized, in-memory key/value store. In the current stable release of AutoIt, the only way to do this without relying on external COM objects (Scripting.Dictionary) is to use a dynamically-sized two-dimensional array. (Or two one-dimensional dynamically-sized arrays, but we'll not get into that as there's not really a good reason to do that over a two-dimensional one.) In the current beta of AutoIt, the map type allows for exactly that, without all of the boilerplate code needed to implement them, as well as a huge speed increase to them since the heavy lifting is being done internally in the interpreter as opposed to being done in AutoIt. One of the key features of this data type is that the amount of things it can store is not a fixed size. This means the more stuff you want to add, the bigger it will grow. The more things you delete from it, the smaller it shrinks. If you need to iterate over a map, it won't have to waste time running through, for example, 9,975 blank entries just to read the 25 populated entries like you would with a 10,000-element fixed-size array.
For those saying that this benchmark is not fair to arrays and that there's a more efficient way to do it so they end up doing much better in the benchmark: I know, this isn't meant to be "arrays vs. maps", it's meant to be "fake maps vs. native maps". There's also some optimization that can be done with my FakeMap code, because ReDim is actually pretty slow, but adding that would make the example code harder to read while the end result would still be the same.

Link to comment
Share on other sites

  • 2 years later...
8 minutes ago, mobin said:

Very interesting thread. Are Maps still in Beta I wonder?!

Instead of asking here, you should have just looked at the beta page, or downloaded it and answered your own question. 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 1 year later...

Very useful feature! I wonder how much faster maps are compare to ObjCreate("Scripting.Dictionary")?

A little issue though, we can't use ["key"] method to define second and beyond levels

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $mMap[]
Global $mObj[]
$mMap.level1 = $mObj
$mMap['level1'] = $mObj
$mMap.level1.level2 = "blah"
$mMap.level1['level2'] = "blah" ;error: Statement cannot be just an expression

 

Link to comment
Share on other sites

  • 4 years later...
On 6/21/2020 at 8:56 PM, VAN0 said:

 Very useful feature! I wonder how much faster maps are compare to ObjCreate("Scripting.Dictionary")?

A little issue though, we can't use ["key"] method to define second and beyond levels

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $mMap[]
Global $mObj[]
$mMap.level1 = $mObj
$mMap['level1'] = $mObj
$mMap.level1.level2 = "blah"
$mMap.level1['level2'] = "blah" ;error: Statement cannot be just an expression

 

Can't define, but can use defined

Global $mMap[]
Global $mObj[]
$mMap.el1 = $mObj
$mMap.el2 = $mObj

$mMap.el1.el11 = "blah "
$mMap.el2.el21 = "blah2 "

MsgBox($MB_OK, "", $mMap.el1.el11 & $mMap.el2.el21 & $mMap.el2["el21"])

; Result:  "blah blah2 blah2 "

 

Edited by Serg2000mr
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...