[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: getting the hex out...



PureBytes Links

Trading Reference Links

Tuzo, Bill,

It is for Indicator mode, and it must get recalculated once each  
pass.  I need a hash of a specified file paths that may or may not  
change during passes.

You can have two different files of the same name that are unique due  
to being located in different folders.  In static variables,  
everything is in essence in the same folder.  I have to append what is  
essentially a path string to each name to make it unique.  However,  
path strings can be large, and I have hundreds of these variables, so  
I wanted to compress the path string down to a few characters with a  
insignificant chance of a collision.  The key generated must always be  
the same for the same path string.  I have the simple calculation, now  
just to generate the string from the number.

I played around with AFL for a few hours and came to the conclusion  
that it can't be done easily.  The best I could do was generate a 22  
bit key.  So I switched to jScript (which I don't know much about) and  
painstakingly fought my way through the problem for a few hours with  
MS documentation.  I finally found an online reference cheat sheet  
that I could read quickly to find the right jScript operators and  
syntax at http://javascript-reference.info/

Piece of cake after that.  Here is what I came up with:

// BDKR algorithm based on Brian Kernighan and Dennis Ritchie's work
// Returns a six character 0-9,A-V (30 bit) key string from any length  
input string
<%
function Hash6String(str){
	var Hash = 0;
	for(i=0; i<str.length; i++){
		Hash = (Hash * 131 + str.charCodeAt(i)) & 0x3FFFFFFF;
	}
	return Hash.toString(32).toUpperCase();
}
%>

BR,
Dennis

On Aug 8, 2008, at 1:47 AM, tuzo_wilson wrote:

> --- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@xxx> wrote:
>
>> I have a problem where I need to make my static variable names unique
>> by appending a unique key string to them.  The key is generated from
>
> I'm assuming this is at runtime.  Would a GUID suit your purposes?
> e.g. MyVar1_8EA7256DFE214820AAB1BE58E2898A0A
>
> In JScript:
>
> function CreateGuid()
> {
>    var typeLib = new ActiveXObject("Scriptlet.TypeLib");
>    var guid = typeLib.Guid.substr(1,36);
>    return guid.replace(/-/g, "");
> }
>
>
> Tuzo


------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/