public ShortenURL() { hasher = new ShortHashMaker(); if (shortenedURLRepo == null) { shortenedURLRepo = new ShortenedURLRepository(); } }
public GraphHashIdType(IHashMaker hashMaker) { hashMaker.AssertNotNull(nameof(hashMaker)); this._HashMaker = hashMaker; this.Name = "HashID"; this.Description = "A hashed ID."; }
public PerlinNoiseMaker(IHashMaker hashMaker, byte version = 0) { //set default fade function m_delFadeFunction = new del_FadeFunction(FadeFunction.Version[version]); //Init Hash Maker m_HashMaker = hashMaker; }
//Constructor---------------------------------------------------------------- public PerlinNoiseMaker(uint _seed, byte version = 0) { //set default fade function m_delFadeFunction = new del_FadeFunction(FadeFunction.Version[version]); //Init Hash Maker m_HashMaker = new HashMakerBase(_seed); }
public void Init(string Seed) { //Init Hash Maker HashMaker = new HashMakerBase(Seed); //Init Noise Maker NoiseMaker = new PerlinNoiseMaker(HashMaker); Locator <IHashMaker> .ProvideService(HashMaker); Locator <INoiseMaker> .ProvideService(NoiseMaker); }
static void BuildDataBase(string dataFolder, IHashMaker hashMaker, string dataBaseFile, bool shutDown) { if (!Directory.Exists(dataFolder)) { WriteLog(string.Format("'{0}' doesn't exist! ", dataFolder)); return; } DataBase dataBase = new DataBase(hashMaker); dataBase.BuildDataBase(dataFolder); dataBase.SaveInBinary(dataBaseFile); if (shutDown) Utility.ShutDown(); }
public void MakeTexture() { hashMaker = new HashMakerBase(seed); noiseMaker = new PerlinNoiseMaker(hashMaker); m_tex = new Texture2D(m_Width, m_Height); float noise; for (int i = 0; i < m_Width; ++i) { for (int j = 0; j < m_Height; ++j) { noise = noiseMaker.MakeOctave_2D(new Vector2(i + Offset.x, j + Offset.y), m_Frequency, 1, m_Ocatave); Debug.Assert(noise > 0 && noise < 1); if (noise > 0 && noise < 0.2) { m_tex.SetPixel(i, j, Color.yellow); } else if (noise > 0.2 && noise < 0.4) { m_tex.SetPixel(i, j, Color.blue); } else if (noise > 0.4 && noise < 0.6) { m_tex.SetPixel(i, j, Color.green); } else if (noise > 0.6 && noise < 0.8) { m_tex.SetPixel(i, j, Color.yellow); } else if (noise > 0.8 && noise < 0.99) { m_tex.SetPixel(i, j, Color.white); } else { m_tex.SetPixel(i, j, Color.yellow); } } } //m_tex.SetPixel(0, 0, Color.black); Debug.Log(m_tex.GetPixel(0, 0)); m_tex.Apply(); m_renderer.material.mainTexture = m_tex; }
static void AppendData(string indexFile, IHashMaker hashMaker, string dataFolder) { if (!Directory.Exists(dataFolder)) { WriteLog(string.Format("'{0}' doesn't exist! ", dataFolder)); return; } if (!File.Exists(indexFile)) { WriteLog(string.Format("'{0}' file doesn't exist! ", indexFile)); return; } DataBase dataBase = new DataBase(hashMaker); dataBase.CheckDuplicate = true; dataBase.Load(indexFile); dataBase.BuildDataBase(dataFolder); dataBase.Save(indexFile); }
// Traverse the Json object in a deterministic way private static void ChecksumJson(Context ctx, IHashMaker hash, JsonElement je) { switch (je.ValueKind) { case JsonValueKind.Array: hash.AppendStartArray(); foreach (var element in je.EnumerateArray()) { ChecksumJson(ctx, hash, element); } hash.AppendEndArray(); break; case JsonValueKind.Object: hash.AppendStartObj(); // Server has bug where it double emits the same property! // Only use once in checksum. HashSet <string> propertyNames = new HashSet <string>(); // Need to determinsitically order the properties. foreach (var prop in je.EnumerateObject().OrderBy(x => x.Name)) { if (propertyNames.Add(prop.Name)) { var kind = prop.Value.ValueKind; hash.AppendPropName(prop.Name); if (kind == JsonValueKind.String && prop.Name == "InvariantScript") { // Invariant script can contain Formulas. var str2 = prop.Value.GetString(); str2 = NormFormulaWhitespace(str2); hash.AppendData(str2); } else if (kind != JsonValueKind.Null) { ctx.Push(prop.Name); ChecksumJson(ctx, hash, prop.Value); ctx.Pop(); } else { } } } hash.AppendEndObj(); break; case JsonValueKind.Number: hash.AppendData(je.GetDouble()); break; case JsonValueKind.False: hash.AppendData(false); break; case JsonValueKind.True: hash.AppendData(true); break; case JsonValueKind.Null: hash.AppendNull(); break; case JsonValueKind.String: var str = je.GetString(); if (ctx.IsJsonDoubleEncoded && !string.IsNullOrWhiteSpace(str)) { var je2 = JsonDocument.Parse(str).RootElement; ChecksumJson(ctx, hash, je2); } else if (ctx.IsXmlDoubleEncoded && !string.IsNullOrWhiteSpace(str)) { var parsedXML = XDocument.Parse(str); var xmlString = parsedXML.ToString(SaveOptions.None).Replace("\r\n", "\n"); hash.AppendData(xmlString); } else { str = str.TrimStart().Replace("\r\n", "\n"); // Normalize line endings. hash.AppendData(str); } break; } }
public static void ConvertIndexFileFromTextToBinary(string textFile, string binaryFile, IHashMaker hashMaker) { DataBase dataBase = new DataBase(hashMaker); dataBase.Load(textFile); dataBase.SaveInBinary(binaryFile); }
public DataBase(IHashMaker hasher) { hashMaker = hasher; CheckDuplicate = false; }
public static void SimpleTest(string indexFile, IHashMaker hashMaker, bool bQuiet) { bool bTextFile = IsTextFile(indexFile); DataBase dataBase = new DataBase(hashMaker); if (bTextFile) dataBase.Load(indexFile); else dataBase.LoadFromBinary(indexFile); dataBase.Quiet = bQuiet; int seconds = 10; while (true) { Console.WriteLine("Press any key to identify a new song, press ESC to exit.\n"); ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Escape) break; byte[] audio = null; Console.WriteLine("Start recording audio from mic ...", seconds); MicRecorder recorder = new MicRecorder(); recorder.Seconds = seconds; recorder.RequestStop = false; recorder.RecStart(); audio = recorder.GetAudioData(); dataBase.UseFFTW = false; Indexing(dataBase, audio); dataBase.UseFFTW = true; Indexing(dataBase, audio); dataBase.UseSort = true; Indexing(dataBase, audio); //dataBase.UseFilter = true; //timeInterval.Reset(); //id = dataBase.GetBestHit(audio, 16); //intervalInSecond = timeInterval.GetDurationInSecond(); //Console.WriteLine("--------------------"); //Console.Write("Final Match ({0}s):\t", intervalInSecond); //if (id < 0) // Console.WriteLine("No match!"); //else // Console.WriteLine(dataBase.GetNameByID(id)); //Console.WriteLine("--------------------"); } }