public static HashNode ProbeHashTable(HashNode[] table, string key, int ha, ProbeMode mode) { if (mode == ProbeMode.Linear) { // if key is not what is expected // then increment address and search there while (table[ha].key != key) { ha++; ha %= table.Length; } } else if (mode == ProbeMode.Random) { int randomSeed = 1234; Random rand = new Random(randomSeed); // if key is not what is expected // then add next random offset to address and search there while (table[ha].key != key) { int r = rand.Next(table.Length - 1); ha = (ha + r) % table.Length; } } return(table[ha]); }
public static void InsertIntoHashTable(HashNode[] table, string key, int ha, ProbeMode mode) { int originalAddress = ha; int probes = 0; if (mode == ProbeMode.Linear) { while (!string.IsNullOrEmpty(table[ha].key)) { ha++; ha %= table.Length; probes++; } } else if (mode == ProbeMode.Random) { int randomSeed = 1234; Random rand = new Random(randomSeed); while (!string.IsNullOrEmpty(table[ha].key)) { int r = rand.Next(table.Length - 1); ha = (ha + r) % table.Length; probes++; } } table[ha].key = key; table[ha].firstHashAddress = originalAddress; table[ha].probes = probes + 1; }
public override void RehashNodes() { // sends all nodes to rehash while (nodesBucket.transform.childCount != 0) { Transform child = nodesBucket.transform.GetChild(0); Rehash.instance.RehashNode(child.GetComponent <Node>()); } // resets bracket bracket.transform.position = transform.position + transform.right; Mode = ProbeMode.NEW; }
public static float CalculateExpectedProbes(int numKyes, int tableSize, ProbeMode mode) { float e = -1; float a = (float)numKyes / (float)tableSize; if (mode == ProbeMode.Linear) { e = (1 - a / 2) / (1 - a); } else if (mode == ProbeMode.Random) { e = -(1 / a) * (float)Math.Log(1 - a); } return(e); }
private bool SwitchProbeMode() { m_mode = (ProbeMode)(((int)m_mode + 1) % 3); ResizeProbe(0, 0); return(true); }
public override void OnTick() { // triggers pin to push pushAnim.SetTrigger("push"); if (node != null) { if (node.deleter) { // if flag matches bucket (green or yellow) if (node.probeFlags.Contains(mode)) { // kills itslef on bracket node.SetDirection(transform.right); node.SetProbeAcceptModes(0); nodeValue = ""; } // if node matches bucket's node else if (Mode == ProbeMode.OCCUPIED && node.GetValue().Equals(nodeValue)) { // destroys the other node node.SetDirection(transform.right); node.SetProbeAcceptModes(0); nodeValue = ""; // marks the bucket as used Mode = ProbeMode.USED; } // probe else { // probe GameObject nextBucket = BuildManager.instance.GetNextBucket(index).nodesBucket; ViewManager.instance.LerpCam(nextBucket.transform.position + new Vector3(0, 0, -10)); node.Teleport(nextBucket); node.SetProbeAcceptModes(1); } } else { // if flag matches bucket if (node.probeFlags.Contains(mode)) { // insert node.SetDirection(transform.right); Mode = ProbeMode.OCCUPIED; node.SetProbeAcceptModes(0); nodeValue = node.GetValue(); } // if node matches bucket's node else if (Mode == ProbeMode.OCCUPIED && node.GetValue().Equals(nodeValue)) { // insert node.SetDirection(transform.right); node.SetProbeAcceptModes(0); } // probe else { // probe GameObject nextBucket = BuildManager.instance.GetNextBucket(index).nodesBucket; ViewManager.instance.LerpCam(nextBucket.transform.position + new Vector3(0, 0, -10)); node.Teleport(nextBucket); node.SetProbeAcceptModes(1); } } } }
private void Start() { pushAnim.speed = TickManager.tickSpeed; maxCapacity = 1; Mode = ProbeMode.NEW; }
protected virtual void Update() { Ray ray = new Ray(transform.position, transform.forward); RaycastHit hitInfo; bool bHit = Physics.Raycast(ray, out hitInfo, UIlayerMask); float distance = 100.0f; if(bHit) { distance = hitInfo.distance; if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { if (!willExit) { willExit = true; // active info box } else { willExit = false; // deactivate info box } } if (willExit && triggerTapped) // if grip button has been pressed { Debug.Log("Probe Mode should be activated."); //info box should show inParent = hitInfo.collider.gameObject.GetComponentInParent<ProbeMode>(); savedBone = hitInfo.collider.gameObject; if (inParent != null && willExit) // savedBone.GetComponent<ProbeMode>() != null || { savedBone.GetComponentInParent<ProbeMode>().OnEnter(savedBone); willExit = true; } } if (!willExit) // if grip button has been pressed again { Debug.Log("Probe Mode should be deactivated."); // no info box if (inParent != null) { savedBone.GetComponentInParent<ProbeMode>().OnExit(savedBone); } willExit = false; } // ugly, but has to do for now if(_distanceLimit > 0.0f) { distance = Mathf.Min(distance, _distanceLimit); bHit = true; } Vector2 triggerPosition = controller.GetAxis(EVRButtonId.k_EButton_SteamVR_Trigger); bool triggerTapped = triggerPosition.x > 0.5f; if (triggerTapped) { // || HandMenuL.activeSelf || HandMenuR.activeSelf) { if (this.GetComponent<FixedJoint> ()) { } else { laser.transform.localScale = new Vector3 (laser.transform.localScale.x, laser.transform.localScale.y, distance); laser.transform.localPosition = new Vector3 (0.0f, 0.0f, distance * 0.5f); hitPoint.SetActive (true); laser.SetActive (true); } } else if (HandMenuL.activeSelf || HandMenuR.activeSelf) { laser.transform.localScale = new Vector3 (laser.transform.localScale.x, laser.transform.localScale.y, distance); laser.transform.localPosition = new Vector3 (0.0f, 0.0f, distance * 0.5f); hitPoint.SetActive (true); laser.SetActive (true); } else if (sceneIndex == 0) { // laser always on in load scene laser.transform.localScale = new Vector3 (laser.transform.localScale.x, laser.transform.localScale.y, distance); laser.transform.localPosition = new Vector3 (0.0f, 0.0f, distance * 0.5f); hitPoint.SetActive (true); laser.SetActive (true); }else { hitPoint.SetActive (false); laser.SetActive (false); } if(bHit) { hitPoint.transform.localPosition = new Vector3(0.0f, 0.0f, distance); } // reset the previous distance limit _distanceLimit = -1.0f; }
public static void PrintProbeResults(string fileName, int hastableSize, string[] input, int n, int tableEntries, ProbeMode mode, int lineLength = 50) { int prb = 0, max = 0, total = 0; float avg = 0.0f; int min = 99999; int cnt = 0; string[] probe; while (cnt < n) { probe = ProbeHashTable(fileName, hastableSize, input[cnt], GetHashOld(input[cnt], hastableSize), mode); prb = 0; int.TryParse(probe[3], out prb); total += prb; if (prb < min) { min = prb; } if (prb > max) { max = prb; } cnt++; } avg = (float)total / (float)n; Console.WriteLine("First " + n + " " + mode.ToString() + " Probes: min = " + min + ", max = " + max + ", avg = " + avg.ToString("0.00")); prb = max = total = 0; avg = 0.0f; min = 99999; cnt = 0; while (cnt < n) { probe = ProbeHashTable(fileName, hastableSize, input[tableEntries - 1 - cnt], GetHashOld(input[tableEntries - 1 - cnt], hastableSize), mode); prb = 0; int.TryParse(probe[3], out prb); total += prb; if (prb < min) { min = prb; } if (prb > max) { max = prb; } cnt++; } avg = (float)total / (float)n; Console.WriteLine("Last " + n + " " + mode.ToString() + " Probes: min = " + min + ", max = " + max + ", avg = " + avg.ToString("0.00")); }
public static void PrintProbeResults(HashNode[] table, string[] input, int n, int tableEntries, ProbeMode mode) { int prb = 0, max = 0, total = 0; float avg = 0.0f; int min = 99999; int cnt = 0; while (cnt < n) { prb = ProbeHashTable(table, input[cnt], GetHashOld(input[cnt], table.Length), mode).probes; total += prb; if (prb < min) { min = prb; } if (prb > max) { max = prb; } cnt++; } avg = (float)total / (float)n; Console.WriteLine("First " + n + " " + mode.ToString() + " Probes: min = " + min + ", max = " + max + ", avg = " + avg.ToString("0.00")); prb = max = total = 0; avg = 0.0f; min = 99999; cnt = 0; while (cnt < n) { if (cnt >= input.Length) { break; } prb = ProbeHashTable(table, input[tableEntries - 1 - cnt], GetHashOld(input[tableEntries - 1 - cnt], table.Length), ProbeMode.Linear).probes; total += prb; if (prb < min) { min = prb; } if (prb > max) { max = prb; } cnt++; } avg = (float)total / (float)n; Console.WriteLine("Last " + n + " " + mode.ToString() + " Probes: min = " + min + ", max = " + max + ", avg = " + avg.ToString("0.00")); }
public static string[] ProbeHashTable(string fileName, int hastableSize, string key, int ha, ProbeMode mode, int lineLength = 50) { Stream stream = File.Open(fileName, FileMode.Open, FileAccess.ReadWrite); string[] hash = new string[4]; if (mode == ProbeMode.Linear) { // if key is not what is expected // then increment address and search there while (!(hash = ReadLineHashInfo(stream, ha, lineLength))[1].Equals(key)) { ha++; ha %= hastableSize; } } else if (mode == ProbeMode.Random) { int randomSeed = 1234; Random rand = new Random(randomSeed); while (!(hash = ReadLineHashInfo(stream, ha, lineLength))[1].Equals(key)) { int r = rand.Next(hastableSize - 1); ha = (ha + r) % hastableSize; } } stream.Flush(); stream.Close(); return(hash); }
public static void InsertIntoHashTable(string fileName, int hastableSize, string key, int ha, ProbeMode mode, int lineLength = 50) { Stream stream = File.Open(fileName, FileMode.Open, FileAccess.ReadWrite); int originalAddress = ha; int probes = 0; if (mode == ProbeMode.Linear) { while (!string.IsNullOrEmpty(ReadLineHashInfo(stream, ha, lineLength)[1])) { ha++; ha %= hastableSize; probes++; } } else if (mode == ProbeMode.Random) { int randomSeed = 1234; Random rand = new Random(randomSeed); while (!string.IsNullOrEmpty(ReadLineHashInfo(stream, ha, lineLength)[1])) { int r = rand.Next(hastableSize - 1); ha = (ha + r) % hastableSize; probes++; } } char[] chars = string.Format("{0,-50}", ha + "," + key + "," + originalAddress + "," + (probes + 1)).ToCharArray(); stream.Seek(ha * lineLength, SeekOrigin.Begin); byte[] write = Encoding.Default.GetBytes(chars, 0, lineLength); stream.Write(write, 0, lineLength); stream.Flush(); stream.Close(); }