LanguageExt.Core

LanguageExt.Core Concurrency VectorClock

Contents

enum Relation Source #

The relations two vector clocks may find themselves in.

record VectorClock <A> (Seq<(A, long)> Entries) Source #

where A : IComparable<A>

To create a vector clock, start from Empty or Single and Insert elements into it. As a shortcut, fromList just inserts all the elements in a list, in order.

var vc = VectorClock<char>.Empty;
vc = vc.Insert('a', 1);
vc = vc.Insert('b', 2);
vc == VectorClock<char>.fromList(Seq(('a', 1), ('b', 2)))

Note that, for different keys, the order of insertion does not matter:

fromList(Seq(('a', 1), ('b', 2)) == fromList(Seq(('b', 2), ('a', 1))

Once you have a given vector clock, you can 'lookup' its fields, check that keys are 'member's, or convert it back 'toList' form.

vc.Lookup('a') == Some(1)
vc.Lookup('c') == None

The main operations that you would do with a vector clock are to increment the entry corresponding to the current process and to update the process's vector clock with the 'max' of its and the received message's clocks.

vc.Inc('a') == Some [('a', 2), ('b', 2)]
VectorClock.max( [('a', 1), ('b', 2)], [('c', 3), ('b', 1)] ) == [('a', 1), ('b', 2), ('c' 3)]

Finally, upon receiving different messages, you may wish to discover the relationship, if any, between them. This information could be useful in determining the correct order to process the messages.

VectorClock.relation (fromList [('a', 1), ('b', 2)], fromList [('a', 2), ('b', 2)]) == Causes
VectorClock.relation (fromList [('a', 2), ('b', 2)], fromList [('a', 1), ('b', 2)]) == CausedBy
VectorClock.relation (fromList [('a', 2), ('b', 2)], fromList [('a', 1), ('b', 3)]) == Concurrent

A vector clock is, conceptually, an associative list sorted by the value of the key, where each key appears only once.

Fields

field VectorClock<A> Empty = new(Seq<(A, long)>()) Source #

Properties

property bool IsEmpty Source #

Is the vector clock empty?

property int Count Source #

The number of entries in the vector clock.

property bool Valid Source #

Methods

method bool Equals (VectorClock<A>? rhs) Source #

method int GetHashCode () Source #

method VectorClock<A> Single (A x, long y) Source #

A vector clock with a single element

method VectorClock<A> fromList (Seq<(A x, long y)> list) Source #

Insert each entry in the list one at a time.

method Seq<(A x, long y)> ToSeq () Source #

All the entries in the vector clock. Note that this is /not/ the inverse of 'fromList'

method (Option<long> Value, VectorClock<A> Clock) Extract (A index) Source #

Lookup the value for a key in the vector clock and remove the corresponding entry

method Option<long> Lookup (A index) Source #

Lookup the value for a key in the vector clock.

method bool Contains (A index) Source #

Is a member?

method VectorClock<A> Remove (A index) Source #

Delete

method VectorClock<A> Insert (A index, long value) Source #

Insert or replace the entry for a key.

method Option<VectorClock<A>> Inc (A index) Source #

Increment the entry for a key by 1

method VectorClock<A> Inc (A index, long defaultValue) Source #

Increment the entry for a key by 1

method VectorClock<A> combine ( Func<A, Option<long>, Option<long>, Option<long>> f, VectorClock<A> vc1, VectorClock<A> vc2) Source #

Combine two vector clocks entry-by-entry

Parameters

param f

a function that takes the /key/, the value of the entry in the left hand vector clock, if it exists, the value in the right hand vector clock, if it exists, and, if it wishes to keep a value for this /key/ in the resulting vector clock, returns it.

param vc1

the left hand vector clock

param vc2

he right hand vector clock

returns

method VectorClock<A> Max (VectorClock<A> vc2) Source #

The maximum of the two vector clocks.

method VectorClock<A> max (VectorClock<A> vc1, VectorClock<A> vc2) Source #

The maximum of the two vector clocks.

method Relation Relation (VectorClock<A> vc2) Source #

The relation between the two vector clocks.

method Relation relation (VectorClock<A> vc1, VectorClock<A> vc2) Source #

The relation between the two vector clocks.

method bool Causes (VectorClock<A> vc2) Source #

Short-hand for relation(vc1, vc2) == Relation.Causes

method bool causes (VectorClock<A> vc1, VectorClock<A> vc2) Source #

Short-hand for relation(vc1, vc2) == Relation.Causes

method Option<VectorClock<A>> Diff (VectorClock<A> vc2) Source #

If vc2 causes vc1, compute the smallest vc3

Note that the /first/ parameter is the newer vector clock.

method Option<VectorClock<A>> diff (VectorClock<A> vc1, VectorClock<A> vc2) Source #

If vc2 causes vc1, compute the smallest vc3

Note that the /first/ parameter is the newer vector clock.

class VectorClock Source #

To create a vector clock, start from Empty or Single and Insert elements into it. As a shortcut, fromList just inserts all the elements in a list, in order.

var vc = VectorClock<char>.Empty;
vc = vc.Insert('a', 1);
vc = vc.Insert('b', 2);
vc == VectorClock<char>.fromList(Seq(('a', 1), ('b', 2)))

Note that, for different keys, the order of insertion does not matter:

fromList(Seq(('a', 1), ('b', 2)) == fromList(Seq(('b', 2), ('a', 1))

Once you have a given vector clock, you can 'lookup' its fields, check that keys are 'member's, or convert it back 'toList' form.

vc.Lookup('a') == Some(1)
vc.Lookup('c') == None

The main operations that you would do with a vector clock are to increment the entry corresponding to the current process and to update the process's vector clock with the 'max' of its and the received message's clocks.

vc.Inc('a') == Some [('a', 2), ('b', 2)]
VectorClock.max( [('a', 1), ('b', 2)], [('c', 3), ('b', 1)] ) == [('a', 1), ('b', 2), ('c' 3)]

Finally, upon receiving different messages, you may wish to discover the relationship, if any, between them. This information could be useful in determining the correct order to process the messages.

VectorClock.relation (fromList [('a', 1), ('b', 2)], fromList [('a', 2), ('b', 2)]) == Causes
VectorClock.relation (fromList [('a', 2), ('b', 2)], fromList [('a', 1), ('b', 2)]) == CausedBy
VectorClock.relation (fromList [('a', 2), ('b', 2)], fromList [('a', 1), ('b', 3)]) == Concurrent

A vector clock is, conceptually, an associative list sorted by the value of the key, where each key appears only once.

Methods

method VectorClock<A> Single <A> (A x, long y) Source #

where A : IComparable<A>

A vector clock with a single element

method VectorClock<OrdA, NumB, A, B> Single <OrdA, NumB, A, B> (A x, B y) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

A vector clock with a single element

method VectorClock<A> fromList <A> (Seq<(A x, long y)> list) Source #

where A : IComparable<A>

Insert each entry in the list one at a time.

method VectorClock<OrdA, NumB, A, B> fromList <OrdA, NumB, A, B> (Seq<(A x, B y)> list) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

Insert each entry in the list one at a time.

method VectorClock<A> combine <A> ( Func<A, Option<long>, Option<long>, Option<long>> f, VectorClock<A> vc1, VectorClock<A> vc2) Source #

where A : IComparable<A>

Combine two vector clocks entry-by-entry

Parameters

param f

a function that takes the /key/, the value of the entry in the left hand vector clock, if it exists, the value in the right hand vector clock, if it exists, and, if it wishes to keep a value for this /key/ in the resulting vector clock, returns it.

param vc1

the left hand vector clock

param vc2

he right hand vector clock

returns

method VectorClock<OrdA, NumB, A, B> combine <OrdA, NumB, A, B> ( Func<A, Option<B>, Option<B>, Option<B>> f, VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

Combine two vector clocks entry-by-entry

Parameters

param f

a function that takes the /key/, the value of the entry in the left hand vector clock, if it exists, the value in the right hand vector clock, if it exists, and, if it wishes to keep a value for this /key/ in the resulting vector clock, returns it.

param vc1

the left hand vector clock

param vc2

he right hand vector clock

returns

method VectorClock<A> max <A> (VectorClock<A> vc1, VectorClock<A> vc2) Source #

where A : IComparable<A>

The maximum of the two vector clocks.

method VectorClock<OrdA, NumB, A, B> max <OrdA, NumB, A, B> (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

The maximum of the two vector clocks.

method Relation relation <A> (VectorClock<A> vc1, VectorClock<A> vc2) Source #

where A : IComparable<A>

The relation between the two vector clocks.

method Relation relation <OrdA, NumB, A, B> (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

The relation between the two vector clocks.

method bool causes <A> (VectorClock<A> vc1, VectorClock<A> vc2) Source #

where A : IComparable<A>

Short-hand for relation(vc1, vc2) == Relation.Causes

method bool causes <OrdA, NumB, A, B> (VectorClock<OrdA, NumB, A, B>vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

Short-hand for relation(vc1, vc2) == Relation.Causes

method Option<VectorClock<A>> diff <A> (VectorClock<A> vc1, VectorClock<A> vc2) Source #

where A : IComparable<A>

If vc2 causes vc1, compute the smallest vc3

Note that the /first/ parameter is the newer vector clock.

method Option<VectorClock<OrdA, NumB, A, B>> diff <OrdA, NumB, A, B> (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

If vc2 causes vc1, compute the smallest vc3

Note that the /first/ parameter is the newer vector clock.

record VectorClock <OrdA, NumB, A, B> (Seq<(A, B)> Entries) Source #

where OrdA : struct, Ord<A>
where NumB : struct, Num<B>

To create a vector clock, start from Empty or Single and Insert elements into it. As a shortcut, fromList just inserts all the elements in a list, in order.

var vc = VectorClock<char>.Empty;
vc = vc.Insert('a', 1);
vc = vc.Insert('b', 2);
vc == VectorClock<char>.fromList(Seq(('a', 1), ('b', 2)))

Note that, for different keys, the order of insertion does not matter:

fromList(Seq(('a', 1), ('b', 2)) == fromList(Seq(('b', 2), ('a', 1))

Once you have a given vector clock, you can 'lookup' its fields, check that keys are 'member's, or convert it back 'toList' form.

vc.Lookup('a') == Some(1)
vc.Lookup('c') == None

The main operations that you would do with a vector clock are to increment the entry corresponding to the current process and to update the process's vector clock with the 'max' of its and the received message's clocks.

vc.Inc('a') == Some [('a', 2), ('b', 2)]
VectorClock.max( [('a', 1), ('b', 2)], [('c', 3), ('b', 1)] ) == [('a', 1), ('b', 2), ('c' 3)]

Finally, upon receiving different messages, you may wish to discover the relationship, if any, between them. This information could be useful in determining the correct order to process the messages.

VectorClock.relation (fromList [('a', 1), ('b', 2)], fromList [('a', 2), ('b', 2)]) == Causes
VectorClock.relation (fromList [('a', 2), ('b', 2)], fromList [('a', 1), ('b', 2)]) == CausedBy
VectorClock.relation (fromList [('a', 2), ('b', 2)], fromList [('a', 1), ('b', 3)]) == Concurrent

A vector clock is, conceptually, an associative list sorted by the value of the key, where each key appears only once.

Fields

field VectorClock<OrdA, NumB, A, B> Empty = new(Seq<(A, B)>()) Source #

Empty vector clock

Properties

property bool IsEmpty Source #

Is the vector clock empty?

property int Count Source #

The number of entries in the vector clock.

property bool Valid Source #

Methods

method bool Equals (VectorClock<OrdA, NumB, A, B>? rhs) Source #

method int GetHashCode () Source #

method VectorClock<OrdA, NumB, A, B> Single (A x, B y) Source #

A vector clock with a single element

method VectorClock<OrdA, NumB, A, B> fromList (Seq<(A x, B y)> list) Source #

Insert each entry in the list one at a time.

method Seq<(A x, B y)> ToList () Source #

All the entries in the vector clock. Note that this is /not/ the inverse of 'fromList'

method (Option<B> Value, VectorClock<OrdA, NumB, A, B> Clock) Extract (A index) Source #

Lookup the value for a key in the vector clock and remove the corresponding entry

method Option<B> Lookup (A index) Source #

Lookup the value for a key in the vector clock.

method bool Contains (A index) Source #

Is a member?

method VectorClock<OrdA, NumB, A, B> Remove (A index) Source #

Delete

method VectorClock<OrdA, NumB, A, B> Insert (A index, B value) Source #

Insert or replace the entry for a key.

method Option<VectorClock<OrdA, NumB, A, B>> Inc (A index) Source #

Increment the entry for a key by 1

method VectorClock<OrdA, NumB, A, B> Inc (A index, B defaultValue) Source #

Increment the entry for a key by 1

method VectorClock<OrdA, NumB, A, B> combine ( Func<A, Option<B>, Option<B>, Option<B>> f, VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

Combine two vector clocks entry-by-entry

Parameters

param f

a function that takes the /key/, the value of the entry in the left hand vector clock, if it exists, the value in the right hand vector clock, if it exists, and, if it wishes to keep a value for this /key/ in the resulting vector clock, returns it.

param vc1

the left hand vector clock

param vc2

he right hand vector clock

returns

method VectorClock<OrdA, NumB, A, B> max (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

The maximum of the two vector clocks.

method Relation Relation (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

The relation between the two vector clocks.

method Relation relation (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

The relation between the two vector clocks.

method bool Causes (VectorClock<OrdA, NumB, A, B> vc2) Source #

Short-hand for relation(vc1, vc2) == Relation.Causes

method bool causes (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

Short-hand for relation(vc1, vc2) == Relation.Causes

method Option<VectorClock<OrdA, NumB, A, B>> Diff (VectorClock<OrdA, NumB, A, B> vc2) Source #

If vc2 causes vc1, compute the smallest vc3

Note that the /first/ parameter is the newer vector clock.

method Option<VectorClock<OrdA, NumB, A, B>> diff (VectorClock<OrdA, NumB, A, B> vc1, VectorClock<OrdA, NumB, A, B> vc2) Source #

If vc2 causes vc1, compute the smallest vc3

Note that the /first/ parameter is the newer vector clock.