hash

Convert ten character classification string into four character one in C#

What's the best way to convert (to hash) a string like 3800290030, which represents an id for a classification into a four character one like 3450 (I need to support at max 9999 classes). We will only have less than 1000 classes in 10 character space and it will never grow to more than 10k. The hash needs to be unique and always the sam...

Exporting MATLAB solution to mutiple sheets in the same excel file

Now I'm implementing a parametric study using MATLAB in connection with COMSOL. I use 3 nested for loops to study the effect of three different independent parameters on multiple dependent parameters (e.g. A,B, C,D, ..) where A, B, C, D are 2d arrayes. The problem which I face at the time being is: How to export the solution 2d arrayes t...

How to algorithmically partion a keyspace?

This is related to consistent hashing and while I conceptually understand what I need to do, I'm having a hard time translating this into code. I'm trying to divide a given keyspace (say, 128 bits) into equal sized partitions. I want the upper bound (highest key) of each partition. Basically, how would I complete this? #define KEYSPAC...

building a hash lookup table during `git filter-branch` or `git-rebase`

I've been using the SHA1 hashes of my commits as references in documentation, etc. I've realized that if I need to rewrite those commits, I'll need to create a lookup table to correspond the hashes for the original repo with the hashes for the filtered repo. Since these are effectively UUID's, a simple lookup table would do. I think t...

What language is this?

got some keys with patterns like 4AC59BAA63A64327DCE12C0B2CD1A397 and B9E685495FECFC9854E7DBA508D91213 they have 32 chars and i would like not to decrypt then but to be able to make my own, its something like a hash of a file ...

iPhone: fast hash function for storing web images (url) as files (hashed filenames)

What is a fast hash function available for the iPhone to hash web urls (images)? I'd like to store the cached web image as a file with a hash as the filename, because I suppose the raw web url could contain strange characters that could cause problems on the file system. The hash function doesn't need to be cryptographic, but it defi...

Why a different SHA-1 for the same file under windows or linux?

Why on the same machine computing the SHA-1 hash of the same file produces two completely different SHA-1 hashes in windows and inside a msysgit Git bash? Doesn't the SHA-1 algorithm was intended to produce the same hash for the same file in all OSes? On windows (with HashCheck): File hello.txt 22596363b3de40b06f981fb85d82312e8c0ed511...

Combining Java hashcodes into a "master" hashcode

I have a vector class with hashCode() implemented. It wasn't written by me, but uses 2 prime numbers by which to multiply the 2 vector components before XORing them. Here it is: /*class Vector2f*/ ... public int hashCode() { return 997 * ((int)x) ^ 991 * ((int)y); //large primes! } ...As this is from an establ...

In Ruby, how do I make a hash from an array?

I have a simple array: arr = ["apples", "bananas", "coconuts", "watermelons"] I also have a function f that will perform an operation on a single string input and return a value. This operation is very expensive, so I would like to memoize the results in the hash. I know I can make the desired hash with something like this: h = {} a...

C# how to calculate hashcode from an object reference.

Folks, here's a thorny problem for you! A part of the TickZoom system must collect instances of every type of object into a Dictionary<> type. It is imperative that their equality and hash code be based on the instance of the object which means reference equality instead of value equality. The challenge is that some of the objects in ...

Multidimensional hash in DB2

Hello, Can you tell me how are the hash structures for multidimensional data are realized in DB2? 10x ...

merging arrays of hashes

I have two arrays, each holding arrays with attribute hashes. Array1 => [[{attribute_1 = A}, {attribute_2 = B}], [{attribute_1 = A}, {attribute_4 = B}]] Array2 => [{attribute_3 = C}, {attribute_2 = D}], [{attribute_3 = C, attribute_4 = D}]] Each array in the array is holding attribute hashes for an object. In the above example, the...

C: getopt with list of acceptable optarg. What is the best practice?

Hi, I am writing a C program which is a frontend to a myriad tools. This fronted will be launched like this: my-frontend --action <AN ACTION> As all the tools have the same prefix, let say for this example this prefix is "foo". I want to concatenate "AN ACTION" to this prefix and exec this (if the tool exists). I have written someth...

New Perl user: using a hash of arrays

I'm doing a little datamining project where a perl script grabs info from a SQL database and parses it. The data consists of several timestamps. I want to find how many of a particular type of timestamp exist on any particular day. Unfortunately, this is my first perl script, and the nature of perl when it comes to hashes and arrays is c...

Question : Perl map - need to map a array into a hash as arrayelement->array_index

Hi folks. I have a array like this: my @arr = ("Field3","Field1","Field2","Field5","Field4"); Now i use map like below , where /DOSOMETHING/ is the answer am seeking. my %hash = map {$_ => **/DOSOMETHING/** } @arr Now I require the hash to look like below: Field3 => 0 Field1 => 1 Field2 => 2 Field5 => 3 Field4 => 4 Any help? ...

Constructing a hash table/hash function.

Hi, I would like to construct a hash table that looks up keys in sequences (strings) of bytes ranging from 1 to 15 bytes. I would like to store an integer value, so I imagine an array for hashing would suffice. I'm having difficulty conceptualizing how to construct a hash function such that given the key would give an index into the ar...

Java - Make an object collection friendly

If an object holds a unique primary key, what interfaces does it need to implement in order to be collection friendly especially in terms of being efficiently sortable, hashable, etc...? If the primary key is a string, how are these interfaces best implemented? Thanks! ...

dereferencing hash from params

Hi, This code works: my $href = shift @_; # get reference to hash my %h = %{$href}; # dereference hash This one does not: my %h = %{shift @_}; As well as this one: my %h = ${$_[0]} Why? ============================= One more time to be precisly: 1 #!/usr/bin/perl -w 2 use strict; 3 use warnings; 4 ...

Perl Hash Slice, Replication x Operator, and sub params

Ok, I understand perl hash slices, and the "x" operator in Perl, but can someone explain the following code example from here (slightly simplified)? sub test{ my %hash; @hash{@_} = (undef) x @_; } Example Call to sub: test('one', 'two', 'three'); This line is what throws me: @hash{@_} = (undef) x @_; It is creating a ha...

Hashing and salting values

I am developing a small web app that internally authenticates users. Once the user is authenticated my web app then passes some information such as userID and Person's name to a third party web application. The third party developer is suggesting that we hash and salt the values. Forgive my ignorance, but what exactly does that mean? ...