Search code examples
rebolrebol3red-lang

Add to map inside of parse dialect


I want to create a map where a hash is associated to a url in order to check if some url is or is not in the map. If it's not yet in the map, add it (and the url) to it.

parseContainer: func [cstr [string!]] [
    parse cstr [
        thru "<a href=" to {"}
        thru "http://" copy quarto_url to {"}
        (
            quarto_hash: checksum/method to-binary quarto_url 'md5
            old: find words-of checksums 'quarto_hash
            if not old [append checksums [quarto_hash quarto_url ]]
        )
    ]
]

But the words quarto_hash and quarto_url are not converted to their values. This is maybe not the simplest approach for the problem, so I'll wait for your input. One other question: is map able to address insertion and search of elements quickly for thousands of elements, or is there any other more appropriate type?

FYI, I'm using Rebol3, but included the Red tag as well because I'll also be using Red in a short future. What is the best approach for this?


Solution

  • You need to reduce the words quarto_hash and quarto_url

    if not old [append checksums reduce [quarto_hash quarto_url ]]
    

    There is also no need to extract the words of the map, you should be faster with a select direct on the map

    I would use

    if not select checksums quarto_hash [
        append checksums reduce [quarto_hash quarto_url ]
    ]