#target
یک شنبه 19 آذر 1391, 23:43 عصر
سلام خدمت کاربران بخش #C
بنده برنامه نویس C هستم و به دلایلی نیاز دارم تابع String.GetHashCode که در دات نت هست رو اونجا پیاده سازی کنم
سرچ کردم ی کد پیدا کرده ولی نتیجه یا چیزی که دات نت میده تفاوت داره !
الگوریتم این تابع رو میخواستم
تابعی که من گیر آوردم {
fixed (char* str = this)
{
char* chPtr = str;
int num = 352654597;
int num2 = num;
int* numPtr = (int*)chPtr;
for (int i = this.Length; i > 0; i -= 4)
{
num = (((num << 5) + num) + (num >> 27)) ^ numPtr[0];
if (i <= 2)
{
break;
}
num2 = (((num2 << 5) + num2) + (num2 >> 27)) ^ numPtr[1];
numPtr += 2;
}
return (num + (num2 * 1566083941));
}
}
بنده برنامه نویس C هستم و به دلایلی نیاز دارم تابع String.GetHashCode که در دات نت هست رو اونجا پیاده سازی کنم
سرچ کردم ی کد پیدا کرده ولی نتیجه یا چیزی که دات نت میده تفاوت داره !
الگوریتم این تابع رو میخواستم
تابعی که من گیر آوردم {
fixed (char* str = this)
{
char* chPtr = str;
int num = 352654597;
int num2 = num;
int* numPtr = (int*)chPtr;
for (int i = this.Length; i > 0; i -= 4)
{
num = (((num << 5) + num) + (num >> 27)) ^ numPtr[0];
if (i <= 2)
{
break;
}
num2 = (((num2 << 5) + num2) + (num2 >> 27)) ^ numPtr[1];
numPtr += 2;
}
return (num + (num2 * 1566083941));
}
}