Click here to Skip to main content
15,905,504 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with Mutex in multithreading Application Pin
mcljava29-Nov-05 12:57
mcljava29-Nov-05 12:57 
QuestionHow do i get directx to play a video, without opening a new window? Pin
Anthony Mushrow22-Nov-05 6:01
professionalAnthony Mushrow22-Nov-05 6:01 
AnswerRe: How do i get directx to play a video, without opening a new window? Pin
leppie22-Nov-05 19:00
leppie22-Nov-05 19:00 
QuestionCapture console output Pin
Kash22-Nov-05 5:42
Kash22-Nov-05 5:42 
AnswerRe: Capture console output Pin
S. Senthil Kumar22-Nov-05 5:57
S. Senthil Kumar22-Nov-05 5:57 
GeneralRe: Capture console output Pin
Kash22-Nov-05 23:40
Kash22-Nov-05 23:40 
QuestionHow to playback file wave by tapi Pin
sharapova22-Nov-05 4:51
sharapova22-Nov-05 4:51 
QuestionHash Code calculation Pin
J4amieC22-Nov-05 4:20
J4amieC22-Nov-05 4:20 
Hi,

I have one of those real computer-science-type questions, and seeing as I never went to uni I missed that class Laugh | :laugh:

I have 4 types of object which represent entities from my database, and as such each has an 'Id' property which is my unique key from the database - therefore it is a good candidate for the GetHashCode override for that object - ie/

class MyEntity
{
   private int id; // key from db

   public int GetHashCode()
   {
      return id;
   }
}


Now, I have another object which is composed of my 4 Entities

class MyComposite
{
   private MyFirstEntity firstEntity;
   private MySecondEntity secondEntity;
   private MyThirdEntity thirdEntity;
   private MyFourthEntity fourthEntity;
}


each type of entity overrides GetHashCode in the manner described above.

Now my question is, I am trying to generate a unique has code for MyComposite, which does not itself have a unique database key to use - without much success. The problem is 2 fold

1) In the example above, MyFirstEntity & MySecondEntity can have an id of -1 (meaning it is not present in the database) and I think this is affecting my calculations (see below)
2) As these are all db identities from differing tables they can of course all have Id's in the range 1..N - again I think this is causing my duplicate keys problem.

What I have tried so far:

firstEntity.GetHashCode() ^ secondEntity.GetHashCode() ^ thirdEntity.GetHashCode() ^ fourthEntity.GetHashCode()

This caused obvious duplicates for differing combinations of entities very early on.

The other attempt, based on an obvious google search, appeared to work at first but after further testing with a wider range of numbers caused many duplicates.

double e1Hash = (firstEntity.GetHashCode() * Math.Pow(100,3));
double e2Hash = (secondEntity.GetHashCode() * Math.Pow(100,2));
double e3Hash = (thirdEntity.GetHashCode() * 100);
double e4Hash = fourthEntity.GetHashCode();
int hash = (int)((Math.Abs(e1Hash+e2Hash+e3Hash+e4Hash ))%int.MaxValue);


I did change the value "100" to be a high prime (41 I used) after reading another very mathmatical paper from a university... but it did not affect things that much.

I tried removing the call to Math.Abs thinking that it may spread the range over -ve and +ve numbers but alas this did not fix my problem.

Any clues very much appretiated and TIA!
AnswerRe: Hash Code calculation Pin
Stanciu Vlad22-Nov-05 6:08
Stanciu Vlad22-Nov-05 6:08 
GeneralRe: Hash Code calculation Pin
J4amieC22-Nov-05 6:23
J4amieC22-Nov-05 6:23 
GeneralRe: Hash Code calculation Pin
Stanciu Vlad22-Nov-05 7:40
Stanciu Vlad22-Nov-05 7:40 
GeneralRe: Hash Code calculation Pin
Leslie Sanford22-Nov-05 9:57
Leslie Sanford22-Nov-05 9:57 
Questionapplication version (major and minor) c# winform Pin
fady_sayegh22-Nov-05 2:34
fady_sayegh22-Nov-05 2:34 
AnswerRe: application version (major and minor) c# winform Pin
Dan Neely22-Nov-05 3:06
Dan Neely22-Nov-05 3:06 
AnswerRe: application version (major and minor) c# winform Pin
J4amieC22-Nov-05 3:17
J4amieC22-Nov-05 3:17 
Question.NET 1.x remoting hell! Pin
Bob Stanneveld22-Nov-05 2:32
Bob Stanneveld22-Nov-05 2:32 
AnswerRe: .NET 1.x remoting hell! Pin
S. Senthil Kumar22-Nov-05 3:56
S. Senthil Kumar22-Nov-05 3:56 
GeneralRe: .NET 1.x remoting hell! Pin
Bob Stanneveld22-Nov-05 22:43
Bob Stanneveld22-Nov-05 22:43 
QuestionEval equivalent in C# Pin
zaboboa22-Nov-05 2:11
zaboboa22-Nov-05 2:11 
AnswerRe: Eval equivalent in C# Pin
Joshua Quick22-Nov-05 7:41
Joshua Quick22-Nov-05 7:41 
QuestionListen to serial port and read RFID kit Pin
Tyler4522-Nov-05 2:08
Tyler4522-Nov-05 2:08 
Questiondwg files to emf format Pin
theladsmith22-Nov-05 1:59
theladsmith22-Nov-05 1:59 
QuestionTips on how to handle Source Contol Pin
anderslundsgard21-Nov-05 23:21
anderslundsgard21-Nov-05 23:21 
AnswerRe: Tips on how to handle Source Contol Pin
mav.northwind22-Nov-05 2:00
mav.northwind22-Nov-05 2:00 
GeneralRe: Tips on how to handle Source Contol Pin
anderslundsgard24-Nov-05 4:36
anderslundsgard24-Nov-05 4:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.