Hi,
Following a recent discussion with BaseX team, here is a description of a problem that I don't know how to solve efficiently from within Xquery or BaseX Xquery extensions like map:module. Thus, any suggestion are welcomed !
The problem is the following : I want to write an XQUERY module called HashSet, implementing the XQUERY version of HashSet (I mean the JAVA object HashSet, or std::set in C++).
An HashSet is indeed a map specialization. Thus a suggestion is to use the BaseX map:module. However, I don't know how to use it efficiently. The reasons are the following : This HashSet module
1) must expose a method "hashset:new()" to allocate memory dynamically. The map:module provides the function map:new, this point is ok, I can wrap that.
2) This module must expose a method "hashset:clear($hashset)" to de-allocate memory dynamically. The map:module provides the function map:remove, and I could remove all elements. However this point is ko for me, as, AFAIU (as far as I understand), map:remove copy an the references from a map object into a smaller map object. It does not dealllocate memory, leading to poor overall performances.
3) must expose a method "hashset:add($hashset,$element)" to add memory dynamically. Through map:module, the only possibility that I see is to wrap it as map:new($hashset, map:entry($element,$dummyboolean)). Here too, a in-memory copy is done, leading to poor overall performances.
XQUERY is a very attractive langage to me. However, its very nature is to be a functional langage. The main inconvenients to working with XQUERY for me are : - first : its dynamic memory management (the in-memory printfoot of my XQUERY executables are usually tremendous). - second : it lacks powerful libraries, as complete math modules.
However, I might miss something ? Do not hesitate to teach me some XQUERY basic !
Cheers
JohnLeM