Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

New Plugin: Hashmap

Jan
20
2
Hello all,

I've written a plugin that provides a fast in-memory hashmap for TCC.

tcc-plugins/hashmap at master · jessepav/tcc-plugins

Compared to UnQLite, it
  • Is not transactional
  • Is not thread-safe
  • Doesn't support cursors
  • Doesn't support data sets larger than memory
  • Only supports textual values
but
  • is faster and lighter
    (For storing and persisting entries, it is much, much faster: in a basic performance test on my old laptop, storing 100 Unicode string entries and saving them to disk took 41 ms using Hashmap and 6731 ms using UnQLite. (This probably involves the @UNQ commands flushing to disk after every call, but for the user who doesn't need ACID guarantees, the result is painful slowness.)
  • provides more convenient syntax for inserting and retrieving entries with commas and quotation marks in their keys or values.
  • allows for multiple in-memory maps
Basically, it's just a typical hashmap, as found in standard programming languages, along with a method to persist them to disk.

Best,
Jesse
 
Last edited:
Hey @jpavel, thanks for the plugin.

For me, it works as advertised.

I did not download the source code, or compile it, but I did download the prebuilt binaries.

I made a slight change to the BasicTest.btm file, at the beginning;
Code:
:: Check if the plugin is loaded
::IFF %@LEN[%@EXECSTR[plugin hashmap >&> NUL]] == 0 THEN
iff not plugin hashmap then
    echo Loading hashmap plugin...^n
    ::plugin /L "%@BATCHDIR[]\..\build\cmake-build\hashmap.dll"
    plugin /L "e:\utils\hashmap.dll"
    set needUnload=1
ELSE
    set needUnload=0
ENDIFF
...and at the end;
Code:
::IF %needUnload==1 (echo Unloading hashmap plugin... & plugin /U hashmap)
if plugin hashmap plugin /u hashmap

Ditto for hashfiletest.btm.

Just my personal preference to use the existing conditional expressions pertaining to plugin.

Joe
 
Hi Joe,

Thanks for testing the plugin, and clueing me in on the PLUGIN conditional expression - I hadn't realized it existed!

I've updated the test scripts on GitHub with that change. (Though I don't automatically unload the plugin at the end of the test script if the script itself didn't load it, so that simply running a test doesn't remove the plugin from your session if you intended to have it there).

Jesse
 
By the way - has anyone gotten the ":mem:" filename to work with the various @UNQ functions? I was writing a performance test, but all attempts to write keys to a ":mem:" UnQLite database throw an IO error.

Thanks,
Jesse
 
By the way - has anyone gotten the ":mem:" filename to work with the various @UNQ functions? I was writing a performance test, but all attempts to write keys to a ":mem:" UnQLite database throw an IO error.

Thanks,
Jesse
I had that problem once, but is was fixed.

Joe
 
Hey @jpavel,
As your Hashmap plugin download does not contain any usage info, I used the SingleFile Add-On for FireFox to capture your Hashmap Github page to a single file for use locally.

I renamed the downloaded .html file to HashmapHelp.html, created an alias;
Code:
alias HashmapHelp=e:\utils\HashmapHelp.html
...so that I have a local copy when needed.

I have placed HashmapHelp.html on my OneDrive, for those that may not use FireFox or the SingleFile Add-On.

Joe
 
Hi @Joe Caverly

I'm glad you brought up that point about documentation: I've updated my build scripts and now the download contains an offline HTML version of the documentation.

Best,
Jesse
 
Could this be used to create a UDF/UDM type of database of functions/methods for tcc features? I'm not familiar with DB and it uses but as the name suggests it could be useful
 
Hi @Kachupp

What exactly do you mean by a UDF/UDM database for tcc features? The hashmap plugin can maintain any, potentially large, mapping of string names to values, so perhaps it would work.
 
User defined functions - User defined methods basically they both mean the same thing
I couldn't with your examples get it to write %@index[1 7,%_dowi,0]
 
Correct. I don't understand what a hashmap does or is. From your examples it can read and write strings for fast retrieval.

The strings I want to write are TCC user defined functions. I’d like somewhere to store these strings and use it as a fast retrieval system aka cache

Is this possible or do I completely miss the stool on its intended use.
 
Here is an example that could clear things up:

Code:
@echo off

setlocal

:: Create a new hashmap
set h=%@hashnew[]

:: Store the function code under key 'func1'
set r=%@hashput[%h,func1/`%@index[1 7,%_dowi,0]`]

:: Turn off nested variable expansion
setdos /X-4

:: Get the code back from the hashmap
set func=%@hashget[%h,func1]

:: Show the code
echos %func

:: Restore nested variable expansion
setdos /X0

:: Evaluate the code
echo ` = `%func

:: Free the map
set r=%@hashfree[%h]

endlocal
 
Try the following adjustment to the code for use in the debugger;
Code:
setlocal

if not isplugin hashmap plugin /l e:\utils\hashmap.dll

:: Create a new hashmap
set h=%@hashnew[]
Replace with the location of your hashmap.dll

Joe
 
Hmm, I load it globally from tsstart. So is the IDE un-aware of its existence?
Will insert "isplugin" test


Sorry My fault I had written the change to tcstart.bat but had not saved it. It was sitting in a another desktop unsaved
 
Last edited:

Similar threads

Back
Top