NetTalk Central

Author Topic: Hashing a QUEUE  (Read 3300 times)

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Hashing a QUEUE
« on: July 24, 2016, 04:19:02 AM »
Hello Bruce and all others,

this a StringTheory-question, but as it concerns my Nettalk SOAPserver / FatClient-project, I will ask here.

When I get a QUEUE back from the server, I want to compare it to the existing on the clientside. If identical, I need no further process.

The Clarion function CHANGES(myQueue) does not do what I want. Manual says:

The CHANGES procedure returns a LONG integer containing a
unique "hash" value for the current QUEUE contents.
Saving this value then later comparing the saved value to the
current return value from CHANGES allows you to easily
detect that the contents of the QUEUE have changed (in any way at all).


However, when I compare two completely unchanged queues, I always get different "hashes".

How about using a StringTheory object for this?
Code: [Select]

LOOP RECORDS(myQueue) Times
  GET(MyQueue, counter)
  st.Append(mQ:RECORD)
  counter += 1
END

hash = st.MD5()

First question: is that possible and useful in general?

My example from above does not work, Clarion says "mQ:RECORD: Unknown Identifier". It works, when I add each field of the queue record on its own.

Second question: Would a new method like .QueueHash(pQueue) a reasonable feature request? The more I think about it, I doubt that. But relentless as I am, I ask anyway.

Thanks for reading,
Wolfgang

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: Hashing a QUEUE
« Reply #1 on: July 27, 2016, 03:46:49 AM »
>> However, when I compare two completely unchanged queues, I always get different "hashes".

I'm guessing the hash returned by CHANGES includes fields you cannot see - like internal index fields and so on. So it's for comparing if _1 queue changed_ not if one queue is the same content as another queue.

I think if you wanted to compare two queues it might be better to make a function to do this.
You could test a bunch of things. For example;


If records(Q1) <> records(Q2) then return false.
loop
  n += 1
  Get(Q1,n)
  Get(Q2,n)
  If Q1 <> Q2 then return false.
end
return true

Calculating a hash for every line takes a bit of time, and seems to me will take longer than simply comparing the queues.
If the queues are not in the same place, then it makes sense to create a hash as you suggest, transfer the hash from one side to the other, and compare the hashes.

Cheers
Bruce