Search Results

Search found 3339 results on 134 pages for 'hash collision'.

Page 46/134 | < Previous Page | 42 43 44 45 46 47 48 49 50 51 52 53  | Next Page >

  • How can I sort a Perl array of array of hashes?

    - by srk
    @aoaoh; $aoaoh[0][0]{21} = 31; $aoaoh[0][0]{22} = 31; $aoaoh[0][0]{23} = 17; for $k (0 .. $#aoaoh) { for $i(0.. $#aoaoh) { for $val (keys %{$aoaoh[$i][$k]}) { print "$val=$aoaoh[$i][$k]{$val}\n"; } } } The output is: 22=31 21=31 23=17 but i expect it to be 21=31 22=31 23=17 Please tell me where is this wrong. Also how do I sort the values so that i get the output as 23=17 22=31 21=31 (if 2 keys have same value then key with higher value come first)

    Read the article

  • Why this code generates different numbers?

    - by frbry
    Hello, I have this function that creates a unique number for hard-disk and CPU combination. DWORD hw_hash() { char drv[4]; char szNameBuffer[256]; DWORD dwHddUnique; DWORD dwProcessorUnique; DWORD dwUniqueKey; char *sysDrive = getenv ("SystemDrive"); strcpy(drv, sysDrive); drv[2] = '\\'; drv[3] = 0; GetVolumeInformation(drv, szNameBuffer, 256, &dwHddUnique, NULL, NULL, NULL, NULL); SYSTEM_INFO si; GetSystemInfo(&si); dwProcessorUnique = si.dwProcessorType + si.wProcessorArchitecture + si.wProcessorRevision; dwUniqueKey = dwProcessorUnique + dwHddUnique; return dwUniqueKey; } It returns different numbers if I format my hard-disk and install a new Windows. Any ideas, why? Thank you. Edit: OK, Got it: This function returns the volume serial number that the operating system assigns when a hard disk is formatted. To programmatically obtain the hard disk's serial number that the manufacturer assigns, use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia property SerialNumber. I should do more research before posting my problems online. Sorry to bother you, let's keep this here in case anybody else can need it.

    Read the article

  • Good PHP / MYSQL hashing solution for large number of text values

    - by Dave
    Short descriptio: Need hashing algorithm solution in php for large number of text values. Long description. PRODUCT_OWNER_TABLE serial_number (auto_inc), product_name, owner_id OWNER_TABLE owner_id (auto_inc), owener_name I need to maintain a database of 200000 unique products and their owners (AND all subsequent changes to ownership). Each product has one owner, but an owner may have MANY different products. Owner names are "Adam Smith", "John Reeves", etc, just text values (quite likely to be unicode as well). I want to optimize the database design, so what i was thinking was, every week when i run this script, it fetchs the owner of a proudct, then checks against a table i suppose similar to PRODUCT_OWNER_TABLE, fetching the owner_id. It then looks up owner_id in OWNER_TABLE. If it matches, then its the same, so it moves on. The problem is when its different... To optimize the database, i think i should be checking against the other "owner_name" entries in OWNER_TABLE to see if that value exists there. If it does, then i should use that owner_id. If it doesnt, then i should add another entry. Note that there is nothing special about the "name". as long as i maintain the correct linkagaes AND make the OWNER_TABLE "read-only, append-new" type table - I should be able create a historical archive of ownership. I need to do this check for 200000 entries, with i dont know how many unique owner names (~50000?). I think i need a hashing solution - the OWNER_TABLE wont be sorted, so search algos wont be optimal. programming language is PHP. database is MYSQL.

    Read the article

  • Mapping words to numbers with respect to definition

    - by thornate
    As part of a larger project, I need to read in text and represent each word as a number. For example, if the program reads in "Every good boy deserves fruit", then I would get a table that converts 'every' to '1742', 'good' to '977513', etc. Now, obviously I can just use a hashing algorithm to get these numbers. However, it would be more useful if words with similar meanings had numerical values close to each other, so that 'good' becomes '6827' and 'great' becomes '6835', etc. As another option, instead of a simple integer representing each number, it would be even better to have a vector made up of multiple numbers, eg (lexical_category, tense, classification, specific_word) where lexical_category is noun/verb/adjective/etc, tense is future/past/present, classification defines a wide set of general topics and specific_word is much the same as described in the previous paragraph. Does any such an algorithm exist? If not, can you give me any tips on how to get started on developing one myself? I code in C++.

    Read the article

  • Java - Make an object collection friendly

    - by DutrowLLC
    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!

    Read the article

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

    - by Xavier Maillard
    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 something but my implementation uses strcmp to test that "AN ACTION" is a valid action. Even if this works, I do not like it. So I am looking for a nicer solution that would do the same. The list of possibilities is pretty small (less than 10) and static (the list is "hardcoded") but I am sure there is a more "C-ish" way to do this (using a struct or something like that). As I am not a C expert, I am asking for your help. Regards

    Read the article

  • How to Iterate in ruby ?

    - by Big Bang Theory
    Hi I would like to iterate @some_value outputs the following result {"Meta"=>{"Query"=>"java", "ResultOffset"=>"1", "NumResults"=>"1", "TotalResults"=>"21931"}} i need to retrieve the Value of each individual value for example java 1 1 21931

    Read the article

  • Arrays/Lists and computing hashvalues (VB, C#)

    - by Jeffrey Kern
    I feel bad asking this question but I am currently not able to program and test this as I'm writing this on my cell-phone and not on my dev machine :P (Easy rep points if someone answers! XD ) Anyway, I've had experience with using hashvalues from String objects. E.g., if I have StringA and StringB both equal to "foo", they'll both compute out the same hashvalue, because they're set to equal values. Now what if I have a List, with T being a native data type. If I tried to compute the hashvalue of ListA and ListB, assuming that they'd both be the same size and contain the same information, wouldn't they have equal hashvalues as well? Assuming as sample dataset of 'byte' with a length of 5 {5,2,0,1,3}

    Read the article

  • Speed of QHash lookups using QStrings as keys.

    - by Ryan R.
    I need to draw a dynamic overlay on a QImage. The component parts of the overlay are defined in XML and parsed out to a QHash<QString, QPicture> where the QString is the name (such as "crosshairs") and the QPicture is the resolution independent drawing. I then draw components of the overlay as they are needed at a position determined during runtime. Example: I have 10 pictures in my QHash composing every possible element in a HUD. During a particular frame of video I need to draw 6 of them at different positions on the image. During the next frame something has changed and now I only need to draw 4 of them but 2 of those positions have changed. Now to my question: If I am trying to do this quickly, should I redefine my QHash as QHash<int, QPicture> and enumerate the keys to counteract the overhead caused by string comparisons; or are the comparisons not going to make a very big impact on performance? I can easily make the conversion to integer keys as the XML parser and overlay composer are completely separate classes; but I would like to use a consistent data structure across the application. Should I overcome my desire for consistency and re-usability in order to increase performance? Will it even matter very much if I do?

    Read the article

  • [PHP] md5(uniqid) makes sense for random unique tokens?

    - by Exception e
    I want to create a token generator that generates tokens that cannot be guessed by the user and that are still unique (to be used for password resets and confirmation codes). I often see this code; does it make sense? md5(uniqid(rand(), true)); According to a comment uniqid($prefix, $moreEntopy = true) yields first 8 hex chars = Unixtime, last 5 hex chars = microseconds. I don't know how the $prefix-parameter is handled.. So if you don't set the $moreEntopy flag to true, it gives a predictable outcome. QUESTION: But if we use uniqid with $moreEntopy, what does hashing it with md5 buy us? Is it better than: md5(mt_rand())

    Read the article

  • How do I call a function name that is stored in a hash in Perl?

    - by Ether
    I'm sure this is covered in the documentation somewhere but I have been unable to find it... I'm looking for the syntactic sugar that will make it possible to call a method on a class whose name is stored in a hash (as opposed to a simple scalar): use strict; use warnings; package Foo; sub foo { print "in foo()\n" } package main; my %hash = (func => 'foo'); Foo->$hash{func}; If I copy $hash{func} into a scalar variable first, then I can call Foo->$func just fine... but what is missing to enable Foo->$hash{func} to work? (EDIT: I don't mean to do anything special by calling a method on class Foo -- this could just as easily be a blessed object (and in my actual code it is); it was just easier to write up a self-contained example using a class method.) EDIT 2: Just for completeness re the comments below, this is what I'm actually doing (this is in a library of Moose attribute sugar, created with Moose::Exporter): # adds an accessor to a sibling module sub foreignTable { my ($meta, $table, %args) = @_; my $class = 'MyApp::Dir1::Dir2::' . $table; my $dbAccessor = lcfirst $table; eval "require $class" or do { die "Can't load $class: $@" }; $meta->add_attribute( $table, is => 'ro', isa => $class, init_arg => undef, # don't allow in constructor lazy => 1, predicate => 'has_' . $table, default => sub { my $this = shift; $this->debug("in builder for $class"); ### here's the line that uses a hash value as the method name my @args = ($args{primaryKey} => $this->${\$args{primaryKey}}); push @args, ( _dbObject => $this->_dbObject->$dbAccessor ) if $args{fkRelationshipExists}; $this->debug("passing these values to $class -> new: @args"); $class->new(@args); }, ); } I've replaced the marked line above with this: my $pk_accessor = $this->meta->find_attribute_by_name($args{primaryKey})->get_read_method_ref; my @args = ($args{primaryKey} => $this->$pk_accessor); PS. I've just noticed that this same technique (using the Moose meta class to look up the coderef rather than assuming its naming convention) cannot also be used for predicates, as Class::MOP::Attribute does not have a similar get_predicate_method_ref accessor. :(

    Read the article

  • Ruby/Rails - Add records to an object with each loop iteration / Object vs Arrays

    - by ChrisWesAllen
    I'm trying to figure out how to add records to an existing object for each iteration of a loop. I'm having a hard time discovering the difference between an object and an array. I have this @events = Event.find(1) @loops = Choices.find(:all, :limit => 5) #so loop for 5 instances of choice model for loop in @loops @events = Event.find(:all,:conditions => ["event.id = ?", loop.event_id ]) end I'm trying to add a new events to the existing @events object based on the id of whatever the loop variable is. But the ( = ) operator just creates a new instance of the @events object. I tried ( += ) and ( << ) as operators but got the error "You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil" I tried created an array events = [] events << Event.find(1) @loops = Choices.find(:all, :limit => 5) #so loop for 5 instances of choice model for loop in @loops events << Event.find(:all,:conditions => ["event.id = ?", loop.event_id ]) end But I dont know how to call that arrays attributes within the view With objects I was able do create a loop within the view and call all the attributes of that object as well... <table> <% for event in @events %> <tr> <td><%= link_to event.title, event %></td> <td><%= event.start_date %></td> <td><%= event.price %></td> </tr> <% end %> </table> How could i do this with an array set? So the questions are 1) Whats the difference between arrays and objects? 2) Is there a way to add into the existing object for each iteration? 3) If I use an array, is there a way to call the attributes for each array record within the view?

    Read the article

  • Ajax back button jquery - Need full example step by step.

    - by Latios88
    Hi. I need help supporting back button with jquery ajax.load method. I have tried a couple of plugins but i cant get any of them to work. I am loading my content like this: $('.pagination a').click(function(){ var url = $(this).attr('href'); ajaxLoad(url,null,'.container'); return false; }); Note: ajaxLoad function executes the jquery load method. Many thanks for your help.

    Read the article

  • MD5 password twice

    - by NoviceCoding
    I know MD5's safety is under question lately and this is the reason a lot of people are using salt (I dont understand this at all btw) but I was wondering if you wanted to easily implement a safe system in php can you just md5 something twice? like test 098f6bcd4621d373cade4e832627b4f6 fb469d7ef430b0baf0cab6c436e70375 So basically: $val = 'test'; $val = md5($val); $val = md5($val); Would that solve the whole rainbow security stuff? Is there an easy/noob proof way of making secure database passwords in php?

    Read the article

  • Combining Java hashcodes into a "master" hashcode

    - by Nick Wiggill
    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 established Java library, I know that it works just fine. Then I have a Boundary class, which holds 2 vectors, "start" and "end" (representing the endpoints of a line). The values of these 2 vectors are what characterize the boundary. /*class Boundary*/ ... public int hashCode() { return 1013 * (start.hashCode()) ^ 1009 * (end.hashCode()); } Here I have attempted to create a good hashCode() for the unique 2-tuple of vectors (start & end) constituting this boundary. My question: Is this hashCode() implementation going to work? (Note that I have used 2 different prime numbers in the latter hashCode() implementation; I don't know if this is necessary but better to be safe than sorry when trying to avoid common factors, I guess -- since I presume this is why primes are popular for hashing functions.)

    Read the article

  • Native arrays and computing hashvalues (VB, C#)

    - by Jeffrey Kern
    I feel bad asking this question but I am currently not able to program and test this as I'm writing this on my cell-phone and not on my dev machine :P (Easy rep points if someone answers! XD ) Anyway, I've had experience with using hashvalues from String objects. E.g., if I have StringA and StringB both equal to "foo", they'll both compute out the same hashvalue, because they're set to equal values. Now what if I have a List, with T being a native data type. If I tried to compute the hashvalue of ListA and ListB, assuming that they'd both be the same size and contain the same information, wouldn't they have equal hashvalues as well?

    Read the article

  • x=["key" => "value"]. How does it work in Ruby?

    - by Earlz
    Ok, so I was comparing some stuff in my own DSL to Ruby. One construct they both support is this x=["key" => "value"] Knowing the difference between arrays and hashes, I would think this to be illegal, but the result in Ruby is [{"key" => "value"}] Why is this? And with this kinda syntax why can't you do x=("key" => "value") Why is an array a special case for implicitly created hashes?

    Read the article

  • why doesn't perl sort the hash key in numeric order ?

    - by Haiyuan Zhang
    #!/usr/bin/perl use strict; use warnings; my %hash; foreach ( 1 .. 10 ) { $hash{$_} = $_; } foreach ( sort(keys %hash) ) { print $_ . ": " . "$hash{$_}" . "\n" ; } execute the above code, the result is as below : 1: 1 10: 10 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 Yes, I expect "10: 10" to be the last one taht is printed . So I just need someone to explain why perl give me surprise in this case.

    Read the article

  • how can I display controller's variable (which is on a loop) on .html.erb page? ruby on rails

    - by rrz
    I have the following code listed below in my controller: struc = {'en' => 'english', 'es' => 'espaniol', 'de' => 'germany', 'fr' => 'french', 'it' => 'italy'} struc.each_pair do |key, value| @key=key @value=value end on my application.html.erb I have the following <select name="Language" onchange="location=this.options[this.selectedIndex].value;"> <option value="/<% @key %>/<%= @rem %>"><%= @value %></option> </select> Now how can i make the value of '@key' and '@value' appear recursively display on (application.html.erb)? Thanks in advance

    Read the article

  • c# How to find if two objects are equal

    - by Simon G
    Hi, I'm needing to know the best way to compare two objects and to find out if there equal. I'm overriding both GethashCode and Equals. So a basic class looks like: public class Test { public int Value { get; set; } public string String1 { get; set; } public string String2 { get; set; } public override int GetHashCode() { return Value ^ String1.GetHashCode() ^ String2.GetHashCode(); } public override bool Equals( object obj ) { return GetHashCode() == obj.GetHashCode(); } } So for testing purposes I created two objects: Test t = new Test() { Value = 1, String1 ="One", String2 = "One" }; Test t2 = new Test() { Value = 1, String1 = "Two", String2 = "Two" }; bool areEqual = t.Equals( t2 ); In testing this areEqual returns true event though both objects are different. I realise this is because String1 and String2 are the same value in each object and thus cancels each other out when hashing. Is there a better way off hashing object that the method I have that will resolve my issue?

    Read the article

  • Why this code does not do what I mean?

    - by Mike
    $w = 'self-powering'; %h = (self => 'self', power => 'pau?', ); if ($w =~ /(\w+)-(\w+)ing$/ && $1~~%h && $2~~%h && $h{$2}=~/?$/) { $p = $h{$1}.$h{$2}.'ri?'; print "$w:"," [","$p","] "; } I expect the output to be self-powering: selfpau?ri? But what I get is: self-powering: [ri?] My guess is something's wrong with the code $h{$2}=~/?$/ It seems that when I use $h{$2}!~/?$/ Perl will do what I mean but why I can't get "self-powering: selfpau?ri?"? What am I doing wrong? Any ideas? Thanks as always for any comments/suggestions/pointers :)

    Read the article

  • How to decrypt a password from SQL server?

    - by sef
    I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted string of 'AAAA': 0x0100CF465B7B12625EF019E157120D58DD46569AC7BF4118455D12625EF019E157120D58DD46569AC7BF4118455D How can I convert (decrypt) the output from its origin (which is 'AAAA')?

    Read the article

< Previous Page | 42 43 44 45 46 47 48 49 50 51 52 53  | Next Page >