private Node FindNode(JVTransaction transaction, K key, Node node) { while (node != null && !key.Equals(node.Key)) { node = node.Next.Read(transaction); } return(node); }
private void InsertInBucket(JVTransaction transaction, VBox <Node> bucketVar, Node node) { var curNode = bucketVar.Read(transaction); if (curNode != null) { node.Next.Put(transaction, curNode); } bucketVar.Put(transaction, node); }
public override bool ContainsKey(K key) { JVTransaction transaction; bool result; do { transaction = JVTransaction.Start(); result = FindNode(transaction, key) != null; } while (!transaction.Commit()); return(result); }
public override bool ContainsKey(K key) { var notCommitted = true; Node node = null; while (notCommitted) { var transaction = JVTransaction.Start(); node = FindNode(transaction, key); notCommitted = !transaction.Commit(); } return(node != null); }
private static void JVTest() { var box1 = new VBox <string>("a"); var box2 = new VBox <bool>(false); var notCommited = true; while (notCommited) { var transaction = JVTransaction.Start(); box1.Put(transaction, "Hello world"); var b2Value = box2.Read(transaction); notCommited = !transaction.Commit(); } }
public override bool Remove(K key) { JVTransaction transaction; bool result; do { transaction = JVTransaction.Start(); var bucketIndex = GetBucketIndex(transaction, key); var bucketVar = _buckets.Read(transaction)[bucketIndex]; var firstNode = bucketVar.Read(transaction); result = RemoveNode(transaction, key, firstNode, bucketVar); } while (!transaction.Commit()); return(result); }
private static int JVConcurrentTestInternal() { var box = new VBox <int>(10); var t1 = new Thread(() => { var notCommited = true; while (notCommited) { var transaction = JVTransaction.Start(); if (box.Read(transaction) == 10) { box.Put(transaction, box.Read(transaction) * 10); } else { box.Put(transaction, 5); } notCommited = !transaction.Commit(); } }); var t2 = new Thread(() => { var notCommited = true; while (notCommited) { var transaction = JVTransaction.Start(); box.Put(transaction, 12); notCommited = !transaction.Commit(); } }); t1.Start(); t2.Start(); t1.Join(); t2.Join(); var t = JVTransaction.Start(); var result = box.Read(t); t.Commit(); return(result); }
public override V Get(K key) { JVTransaction transaction; V result; do { transaction = JVTransaction.Start(); var node = FindNode(transaction, key); if (node == null) { throw new KeyNotFoundException("Key not found. Key: " + key); } result = node.Value.Read(transaction);; } while (!transaction.Commit()); return(result); }
public override V Get(K key) { var notCommitted = true; var value = default(V); while (notCommitted) { var transaction = JVTransaction.Start(); var node = FindNode(transaction, key); if (node == null) { throw new KeyNotFoundException("Key not found. Key: " + key); } value = node.Value.Read(transaction); notCommitted = !transaction.Commit(); } return(value); }
private void Resize(JVTransaction transaction) { //Construct new backing array var newBucketSize = _buckets.Read(transaction).Length * 2; var newBuckets = MakeBuckets(newBucketSize); //For each key in the map rehash for (var i = 0; i < _buckets.Read(transaction).Length; i++) { var bucket = _buckets.Read(transaction)[i]; foreach (var node in bucket.Read(transaction)) { var bucketIndex = GetBucketIndex(newBucketSize, node.Key); newBuckets[bucketIndex].Put(transaction, newBuckets[bucketIndex].Read(transaction).Add(node)); } } //Calculate new resize threshold and assign the rehashed backing array _threshold.Put(transaction, CalculateThreshold(newBucketSize)); _buckets.Put(transaction, newBuckets); }
private void Resize(JVTransaction transaction) { //Construct new backing array var newBucketSize = _buckets.Read(transaction).Length * 2; var newBuckets = MakeBuckets(newBucketSize); //For each key in the map rehash for (var i = 0; i < _buckets.Read(transaction).Length; i++) { var bucket = _buckets.Read(transaction)[i]; var node = bucket.Read(transaction); while (node != null) { var bucketIndex = GetBucketIndex(newBucketSize, node.Key); InsertInBucket(transaction, newBuckets[bucketIndex], CreateNode(node.Key, node.Value.Read(transaction))); node = node.Next.Read(transaction); } } //Calculate new resize threshold and assign the rehashed backing array _threshold.Put(transaction, CalculateThreshold(newBucketSize)); _buckets.Put(transaction, newBuckets); }
public override IEnumerator <KeyValuePair <K, V> > GetEnumerator() { var notCommitted = true; IEnumerator <KeyValuePair <K, V> > result = null; while (notCommitted) { var transaction = JVTransaction.Start(); var list = new List <KeyValuePair <K, V> >(_size.Read(transaction)); for (var i = 0; i < _buckets.Read(transaction).Length; i++) { var bucket = _buckets.Read(transaction)[i]; foreach (var node in bucket.Read(transaction)) { list.Add(new KeyValuePair <K, V>(node.Key, node.Value.Read(transaction))); } } result = list.GetEnumerator(); notCommitted = !transaction.Commit(); } return(result); }
private Node FindNode(JVTransaction transaction, K key, int bucketIndex) { return(FindNode(key, _buckets.Read(transaction)[bucketIndex].Read(transaction))); }
private Node FindNode(JVTransaction transaction, K key) { return(FindNode(transaction, key, GetBucketIndex(transaction, key))); }
private int GetBucketIndex(JVTransaction transaction, K key) { return(GetBucketIndex(_buckets.Read(transaction).Length, key)); }
private static void JVSpeedTest() { var b = new VBox <bool>(); var tmb = new TMVar <bool>(); var sw = Stopwatch.StartNew(); for (int i = 0; i < 10000; i++) { bool notCommitted = true; while (notCommitted) { var t = JVTransaction.Start(); b.Put(t, !b.Read(t)); notCommitted = !t.Commit(); } } sw.Stop(); Console.WriteLine("Non system time: " + sw.ElapsedMilliseconds); sw = Stopwatch.StartNew(); for (int i = 0; i < 10000; i++) { JVSTMSystem.Atomic((t) => { if (b.Read(t)) { b.Put(t, false); } else { b.Put(t, true); } }); } sw.Stop(); Console.WriteLine("System time: " + sw.ElapsedMilliseconds); sw = Stopwatch.StartNew(); for (int i = 0; i < 10000; i++) { STMSystem.Atomic(() => { if (tmb.Value) { tmb.Value = false; } else { tmb.Value = true; } }); } sw.Stop(); Console.WriteLine("TL2 time: " + sw.ElapsedMilliseconds); }