Esempio n. 1
0
 public static void InPlaceUpdater(KeyStruct *key, InputStruct *input, ValueStruct *value)
 {
     ValueStruct.AcquireWriteLock(value);
     value->vfield1 += input->ifield1;
     value->vfield2 += input->ifield2;
     ValueStruct.ReleaseWriteLock(value);
 }
Esempio n. 2
0
        static unsafe void Main(string[] args)
        {
            var fht = FasterFactory.Create
                      <KeyStruct, ValueStruct, InputStruct, OutputStruct, Empty, Functions, ICustomFasterKv>
                          (128, new LogSettings {
                LogDevice = FasterFactory.CreateLogDevice(""), MutableFraction = 0.5
            });

            fht.StartSession();

            OutputStruct output = default(OutputStruct);

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            // Upsert item into store, and read it back
            fht.Upsert(&key1, &value, null, 0);
            fht.Read(&key1, null, &output, null, 0);

            if ((output.value.vfield1 != value.vfield1) || (output.value.vfield2 != value.vfield2))
            {
                Console.WriteLine("Error!");
            }
            else
            {
                Console.WriteLine("Success!");
            }

            var key2 = new KeyStruct {
                kfield1 = 15, kfield2 = 16
            };
            var input = new InputStruct {
                ifield1 = 25, ifield2 = 26
            };

            // Two read-modify-write (RMW) operations (sum aggregator)
            // Followed by read of result
            fht.RMW(&key2, &input, null, 0);
            fht.RMW(&key2, &input, null, 0);
            fht.Read(&key2, null, &output, null, 0);

            if ((output.value.vfield1 != input.ifield1 * 2) || (output.value.vfield2 != input.ifield2 * 2))
            {
                Console.WriteLine("Error!");
            }
            else
            {
                Console.WriteLine("Success!");
            }

            fht.StopSession();

            Console.ReadLine();
        }
Esempio n. 3
0
 public static void InitialUpdater(KeyStruct *key, InputStruct *input, ValueStruct *value)
 {
     ValueStruct.Copy((ValueStruct *)input, value);
 }
Esempio n. 4
0
 public static int InitialValueLength(KeyStruct *key, InputStruct *input)
 {
     return(ValueStruct.GetLength(default(ValueStruct *)));
 }
Esempio n. 5
0
 public static void ConcurrentWriter(KeyStruct *key, ValueStruct *src, ValueStruct *dst)
 {
     ValueStruct.AcquireWriteLock(dst);
     ValueStruct.Copy(src, dst);
     ValueStruct.ReleaseWriteLock(dst);
 }
Esempio n. 6
0
 public static void SingleWriter(KeyStruct *key, ValueStruct *src, ValueStruct *dst)
 {
     ValueStruct.Copy(src, dst);
 }
Esempio n. 7
0
 public static void ConcurrentReader(KeyStruct *key, InputStruct *input, ValueStruct *value, OutputStruct *dst)
 {
     ValueStruct.AcquireReadLock(value);
     ValueStruct.Copy(value, (ValueStruct *)dst);
     ValueStruct.ReleaseReadLock(value);
 }
Esempio n. 8
0
 public static void SingleReader(KeyStruct *key, InputStruct *input, ValueStruct *value, OutputStruct *dst)
 {
     ValueStruct.Copy(value, (ValueStruct *)dst);
 }
Esempio n. 9
0
        static unsafe void Main(string[] args)
        {
            // This sample uses the unsafe API of FASTER, and works only for blittable struct types
            // Your structs have to implement certain static methods (see the structs for details)
            // You also define the interface (ICustomFaster) that will be returned by the factory
            // This sample represents the highest performance level for FASTER, at the expense of
            // supporting limited types.

            var fht = FasterFactory.Create
                      <KeyStruct, ValueStruct, InputStruct, OutputStruct, Empty, Functions, ICustomFasterKv>
                          (128, FasterFactory.CreateLogDevice(""), LogMutableFraction: 0.5);

            fht.StartSession();

            OutputStruct output = default(OutputStruct);

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            // Upsert item into store, and read it back
            fht.Upsert(&key1, &value, null, 0);
            fht.Read(&key1, null, &output, null, 0);

            if ((output.value.vfield1 != value.vfield1) || (output.value.vfield2 != value.vfield2))
            {
                Console.WriteLine("Error!");
            }
            else
            {
                Console.WriteLine("Success!");
            }

            var key2 = new KeyStruct {
                kfield1 = 15, kfield2 = 16
            };
            var input = new InputStruct {
                ifield1 = 25, ifield2 = 26
            };

            // Two read-modify-write (RMW) operations (sum aggregator)
            // Followed by read of result
            fht.RMW(&key2, &input, null, 0);
            fht.RMW(&key2, &input, null, 0);
            fht.Read(&key2, null, &output, null, 0);

            if ((output.value.vfield1 != input.ifield1 * 2) || (output.value.vfield2 != input.ifield2 * 2))
            {
                Console.WriteLine("Error!");
            }
            else
            {
                Console.WriteLine("Success!");
            }

            fht.StopSession();

            Console.ReadLine();
        }