private static uint[] GenerateKeys(IMemcachedNode node, int numberOfKeys)
        {
            const int KeyLength = 4;
            const int PartCount = 1; // (ModifiedFNV.HashSize / 8) / KeyLength; // HashSize is in bits, uint is 4 byte long

            var k = new uint[PartCount * numberOfKeys];

            // every server is registered numberOfKeys times
            // using UInt32s generated from the different parts of the hash
            // i.e. hash is 64 bit:
            // 00 00 aa bb 00 00 cc dd
            // server will be stored with keys 0x0000aabb & 0x0000ccdd
            // (or a bit differently based on the little/big indianness of the host)
            string address = node.EndPoint.ToString();
            var    fnv     = new FNV1a();

            for (int i = 0; i < numberOfKeys; i++)
            {
                byte[] data = fnv.ComputeHash(Encoding.ASCII.GetBytes(String.Concat(address, "-", i)));

                for (int h = 0; h < PartCount; h++)
                {
                    k[i * PartCount + h] = BitConverter.ToUInt32(data, h * KeyLength);
                }
            }

            return(k);
        }
Esempio n. 2
0
        private static List <uint> GenerateKeys(MemcachedNode node, int numberOfKeys)
        {
            const int KeyLength = 4;
            const int PartCount = 1;             // (ModifiedFNV.HashSize / 8) / KeyLength; // HashSize is in bits, uint is 4 byte long

            //if (partCount < 1)
            //    throw new ArgumentOutOfRangeException("The hash algorithm must provide at least 32 bits long hashes");

            List <uint> k = new List <uint>(PartCount * numberOfKeys);

            // every server is registered numberOfKeys times
            // using UInt32s generated from the different parts of the hash
            // i.e. hash is 64 bit:
            // 00 00 aa bb 00 00 cc dd
            // server will be stored with keys 0x0000aabb & 0x0000ccdd
            // (or a bit differently based on the little/big indianness of the host)
            string address = node.EndPoint.ToString();

            for (int i = 0; i < numberOfKeys; i++)
            {
                byte[] data = new FNV1a().ComputeHash(Encoding.ASCII.GetBytes(String.Concat(address, "-", i)));

                for (int h = 0; h < PartCount; h++)
                {
                    k.Add(BitConverter.ToUInt32(data, h * KeyLength));
                }
            }

            return(k);
        }
Esempio n. 3
0
 public void CreateTest()
 {
     Assert.NotNull(FNV1a.Create());
     Assert.IsAssignableFrom <FNV1a>(FNV1a.Create());
     Assert.NotNull(FNV1a.Create(FNVBits.Bits32));
     Assert.IsAssignableFrom <FNV1a>(FNV1a.Create(FNVBits.Bits32));
     Assert.NotNull(FNV1a.Create(FNVBits.Bits64));
     Assert.IsAssignableFrom <FNV1a>(FNV1a.Create(FNVBits.Bits64));
     Assert.Throws <NotSupportedException>(() =>
     {
         FNV1a.Create(null);
     });
 }
Esempio n. 4
0
        public void ComputerTest()
        {
            var bytes = Encoding.UTF8.GetBytes("FNV1a-Test");

            var v1 = BitConverter.ToUInt32(FNV1a.Create().ComputeHash(bytes));
            var v2 = BitConverter.ToUInt32(FNV1a.Create().ComputeHash(bytes));

            Assert.Equal(v1, v2);

            var v3 = BitConverter.ToUInt64(FNV1a.Create(FNVBits.Bits64).ComputeHash(bytes));
            var v4 = BitConverter.ToUInt64(FNV1a.Create(FNVBits.Bits64).ComputeHash(bytes));

            Assert.Equal(v3, v4);
        }
Esempio n. 5
0
        private List <uint> GenerateKeys(ClientNode node, int numberOfKeys)
        {
            List <uint> k = new List <uint>(numberOfKeys);

            for (int i = 0; i < numberOfKeys; i++)
            {
                string s = String.Concat(node.Name, "-", i);

                byte[] data = new FNV1a().ComputeHash(Encoding.ASCII.GetBytes(s));

                k.Add(BitConverter.ToUInt32(data, 0));
            }

            return(k);
        }
Esempio n. 6
0
        public static uint GetTexEnvConfigHash(GFShader Shader)
        {
            FNV1a FNV = new FNV1a();

            foreach (PICATexEnvStage Stage in Shader.TexEnvStages)
            {
                FNV.Hash(Stage.Color.ToUInt32());
                FNV.Hash(Stage.Combiner.ToUInt32());
                FNV.Hash(Stage.Operand.ToUInt32());
                FNV.Hash(Stage.Scale.ToUInt32());
                FNV.Hash(Stage.Source.ToUInt32());
                FNV.Hash(Stage.UpdateAlphaBuffer ? 1 : 0);
                FNV.Hash(Stage.UpdateColorBuffer ? 1 : 0);
            }
            FNV.Hash(Shader.TexEnvBufferColor.ToUInt32());
            return(FNV.HashCode);
        }
Esempio n. 7
0
        static void CompileFromTXT(PackageIndex index, string fileName)
        {
            // Info
            Printer.WriteLine("INFO", String.Format("Compiling {0}", Path.GetFileName(fileName)));

            // Read Lines
            string[] lines = File.ReadAllLines(fileName);

            // Loop Lines
            foreach (string line in lines)
            {
                // Trim Line
                string lineTrim = line.Trim();

                // Check for comments
                if (!lineTrim.StartsWith("#") && !String.IsNullOrWhiteSpace(lineTrim))
                {
                    // Hash the string and mask it
                    ulong id = FNV1a.Calculate64(lineTrim) & 0xFFFFFFFFFFFFFFF;

                    // Check for collision
                    if (index.Entries.ContainsKey(id))
                    {
                        // Collision Hit
                        Printer.WriteLine("WARNING", String.Format("Collision Detected: {0:x} - {1}", id, lineTrim));
                        // Skip
                        continue;
                    }

                    // Add to table
                    index.Entries[id] = lineTrim;
                }
            }

            // Save
            index.Save(Path.GetFileNameWithoutExtension(fileName) + ".wni");

            // Info
            Printer.WriteLine("INFO", String.Format("Compiled successfully", fileName));
        }
Esempio n. 8
0
        private static void GenerateHashesForFile(string filepath)
        {
            string newfile = filepath.Remove(filepath.Length - 4, 4); //trim the extension cos I'm lazy

            newfile = $"{newfile}.hash.csv";

            var alllines = File.ReadAllLines(filepath).ToList();

            alllines.RemoveAt(0);

            using (StreamWriter sw = new StreamWriter(newfile))
            {
                sw.WriteLine("RelativePath,FNV1a64Hash"); //header

                foreach (string line in alllines)
                {
                    var result = new List <string>();
                    var splits = line.Split(',').ToList();
                    if (splits.Count != 5)
                    {
                        throw new NotImplementedException();
                    }

                    //path to hash
                    string relPath = splits[1];
                    string hash    = FNV1a.HashFNV1a64(relPath).ToString();

                    //result.Add(splits.First().Split('\\').Last());  //bundlename
                    result.Add(relPath);                            //relativepath
                    result.Add(hash);                               //hash

                    string res = string.Join(",", result);

                    sw.WriteLine(res);
                }
            }
        }
Esempio n. 9
0
        private static int GetMaterialShaderHash(H3DMaterialParams Params)
        {
            FNV1a HashGen = new FNV1a();

            HashGen.Hash(Params.ShaderReference?.GetHashCode() ?? 0);

            HashGen.Hash(Params.TranslucencyKind.GetHashCode());

            HashGen.Hash(Params.TexCoordConfig.GetHashCode());

            HashGen.Hash(Params.FresnelSelector.GetHashCode());

            HashGen.Hash(Params.BumpMode.GetHashCode());
            HashGen.Hash(Params.BumpTexture.GetHashCode());

            HashGen.Hash(Params.Constant0Assignment.GetHashCode());
            HashGen.Hash(Params.Constant1Assignment.GetHashCode());
            HashGen.Hash(Params.Constant2Assignment.GetHashCode());
            HashGen.Hash(Params.Constant3Assignment.GetHashCode());
            HashGen.Hash(Params.Constant4Assignment.GetHashCode());
            HashGen.Hash(Params.Constant5Assignment.GetHashCode());

            HashGen.Hash(Params.LUTInputAbsolute.Dist0.GetHashCode());
            HashGen.Hash(Params.LUTInputAbsolute.Dist1.GetHashCode());
            HashGen.Hash(Params.LUTInputAbsolute.Fresnel.GetHashCode());
            HashGen.Hash(Params.LUTInputAbsolute.ReflecR.GetHashCode());
            HashGen.Hash(Params.LUTInputAbsolute.ReflecG.GetHashCode());
            HashGen.Hash(Params.LUTInputAbsolute.ReflecB.GetHashCode());

            HashGen.Hash(Params.LUTInputSelection.Dist0.GetHashCode());
            HashGen.Hash(Params.LUTInputSelection.Dist1.GetHashCode());
            HashGen.Hash(Params.LUTInputSelection.Fresnel.GetHashCode());
            HashGen.Hash(Params.LUTInputSelection.ReflecR.GetHashCode());
            HashGen.Hash(Params.LUTInputSelection.ReflecG.GetHashCode());
            HashGen.Hash(Params.LUTInputSelection.ReflecB.GetHashCode());

            HashGen.Hash(Params.LUTInputScale.Dist0.GetHashCode());
            HashGen.Hash(Params.LUTInputScale.Dist1.GetHashCode());
            HashGen.Hash(Params.LUTInputScale.Fresnel.GetHashCode());
            HashGen.Hash(Params.LUTInputScale.ReflecR.GetHashCode());
            HashGen.Hash(Params.LUTInputScale.ReflecG.GetHashCode());
            HashGen.Hash(Params.LUTInputScale.ReflecB.GetHashCode());

            HashGen.Hash(Params.LUTDist0TableName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTDist1TableName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTFresnelTableName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTReflecRTableName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTReflecGTableName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTReflecBTableName?.GetHashCode() ?? 0);

            HashGen.Hash(Params.LUTDist0SamplerName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTDist1SamplerName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTFresnelSamplerName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTReflecRSamplerName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTReflecGSamplerName?.GetHashCode() ?? 0);
            HashGen.Hash(Params.LUTReflecBSamplerName?.GetHashCode() ?? 0);

            foreach (PICATexEnvStage Stage in Params.TexEnvStages)
            {
                HashGen.Hash(Stage.Source.Color[0].GetHashCode());
                HashGen.Hash(Stage.Source.Color[1].GetHashCode());
                HashGen.Hash(Stage.Source.Color[2].GetHashCode());
                HashGen.Hash(Stage.Source.Alpha[0].GetHashCode());
                HashGen.Hash(Stage.Source.Alpha[1].GetHashCode());
                HashGen.Hash(Stage.Source.Alpha[2].GetHashCode());

                HashGen.Hash(Stage.Operand.Color[0].GetHashCode());
                HashGen.Hash(Stage.Operand.Color[1].GetHashCode());
                HashGen.Hash(Stage.Operand.Color[2].GetHashCode());
                HashGen.Hash(Stage.Operand.Alpha[0].GetHashCode());
                HashGen.Hash(Stage.Operand.Alpha[1].GetHashCode());
                HashGen.Hash(Stage.Operand.Alpha[2].GetHashCode());

                HashGen.Hash(Stage.Combiner.Color.GetHashCode());
                HashGen.Hash(Stage.Combiner.Alpha.GetHashCode());

                HashGen.Hash(Stage.Scale.Color.GetHashCode());
                HashGen.Hash(Stage.Scale.Alpha.GetHashCode());

                HashGen.Hash(Stage.UpdateColorBuffer.GetHashCode());
                HashGen.Hash(Stage.UpdateAlphaBuffer.GetHashCode());
            }

            HashGen.Hash(Params.TexEnvBufferColor.R.GetHashCode());
            HashGen.Hash(Params.TexEnvBufferColor.G.GetHashCode());
            HashGen.Hash(Params.TexEnvBufferColor.B.GetHashCode());
            HashGen.Hash(Params.TexEnvBufferColor.A.GetHashCode());

            return((int)HashGen.HashCode);
        }
Esempio n. 10
0
		private static uint[] GenerateKeys(IMemcachedNode node, int numberOfKeys)
		{
			const int KeyLength = 4;
			const int PartCount = 1; // (ModifiedFNV.HashSize / 8) / KeyLength; // HashSize is in bits, uint is 4 byte long

			var k = new uint[PartCount * numberOfKeys];

			// every server is registered numberOfKeys times
			// using UInt32s generated from the different parts of the hash
			// i.e. hash is 64 bit:
			// 00 00 aa bb 00 00 cc dd
			// server will be stored with keys 0x0000aabb & 0x0000ccdd
			// (or a bit differently based on the little/big indianness of the host)
			string address = node.EndPoint.ToString();
			var fnv = new FNV1a();

			for (int i = 0; i < numberOfKeys; i++)
			{
				byte[] data = fnv.ComputeHash(Encoding.ASCII.GetBytes(String.Concat(address, "-", i)));

				for (int h = 0; h < PartCount; h++)
				{
					k[i * PartCount + h] = BitConverter.ToUInt32(data, h * KeyLength);
				}
			}

			return k;
		}
Esempio n. 11
0
 /// <summary>
 /// Return the hash of the object
 /// </summary>
 /// <returns>Hash of the object</returns>
 public override int GetHashCode()
 {
     return((int)FNV1a.Hash32(Utils.Latin1Encoding.GetBytes(ToString())));
 }
Esempio n. 12
0
 /// <summary>
 /// Calculate the hash of the raw, binary data of this picture, using FNV-1a
 /// </summary>
 /// <returns>FNV-1a hash of the raw binary data</returns>
 public uint ComputePicHash()
 {
     PictureHash = FNV1a.Hash32(PictureData);
     return(PictureHash);
 }
        private static List<uint> GenerateKeys(MemcachedNode node, int numberOfKeys)
        {
            const int KeyLength = 4;
            const int PartCount = 1; // (ModifiedFNV.HashSize / 8) / KeyLength; // HashSize is in bits, uint is 4 byte long

            //if (partCount < 1)
            //    throw new ArgumentOutOfRangeException("The hash algorithm must provide at least 32 bits long hashes");

            List<uint> k = new List<uint>(PartCount * numberOfKeys);

            // every server is registered numberOfKeys times
            // using UInt32s generated from the different parts of the hash
            // i.e. hash is 64 bit:
            // 00 00 aa bb 00 00 cc dd
            // server will be stored with keys 0x0000aabb & 0x0000ccdd
            // (or a bit differently based on the little/big indianness of the host)
            string address = node.EndPoint.ToString();

            for (int i = 0; i < numberOfKeys; i++)
            {
                byte[] data = new FNV1a().ComputeHash(Encoding.ASCII.GetBytes(String.Concat(address, "-", i)));

                for (int h = 0; h < PartCount; h++)
                {
                    k.Add(BitConverter.ToUInt32(data, h * KeyLength));
                }
            }

            return k;
        }