qwerty787788

DGCJ Message

Aug 6th, 2016
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.44 KB | None | 0 0
  1. // A program you submit to Distributed Code Jam will be compiled by Google, and
  2. // will run on multiple computers (nodes). This library describes the interface
  3. // needed for the nodes to identify themselves and to communicate.
  4. //
  5. // This is the version of the interface for programs written in Java. Your
  6. // program doesn't need to import it and should always use a class name before
  7. // accessing the static methods, e.g.:
  8. // int n = message.NumberOfNodes();
  9. public class message {
  10.  
  11.   // The number of nodes on which the solution is running.
  12.   public static int NumberOfNodes() {
  13.       return 100;
  14.   }
  15.  
  16.   // The index (in the range [0 .. NumberOfNodes()-1]) of the node on which this
  17.   // process is running.
  18.   public static int MyNodeId() {
  19.       return 0;
  20.   }
  21.  
  22.   // In all the functions below, if "target" or "source" is not in the valid
  23.   // range, the behaviour is undefined.
  24.  
  25.   // The library internally has a message buffer for each of the nodes in
  26.   // [0 .. NumberOfNodes()-1]. It accumulates the message in such a buffer through
  27.   // the "Put" methods.
  28.  
  29.   // Append "value" to the message that is being prepared for the node with id
  30.   // "target". The "Int" in PutInt is interpreted as 32 bits, regardless of
  31.   // whether the actual int type will be 32 or 64 bits.
  32.   public static void PutChar(int target, char value) {
  33.      
  34.   }
  35.   public static void PutInt(int target, int value) {
  36.      
  37.   }
  38.   public static void PutLL(int target, long value)
  39.   {
  40.      
  41.   }
  42.  
  43.   // Send the message that was accumulated in the appropriate buffer to the
  44.   // "target" instance, and clear the buffer for this instance.
  45.   //
  46.   // This method is non-blocking - that is, it does not wait for the receiver to
  47.   // call "Receive", it returns immediately after sending the message.
  48.   public static void Send(int target) {
  49.      
  50.   }
  51.  
  52.   // The library also has a receiving buffer for each instance. When you call
  53.   // "Receive" and retrieve a message from an instance, the buffer tied to this
  54.   // instance is overwritten. You can then retrieve individual parts of the
  55.   // message through the Get* methods. You must retrieve the contents of the
  56.   // message in the order in which they were appended.
  57.   //
  58.   // This method is blocking - if there is no message to receive, it will wait for
  59.   // the message to arrive.
  60.   //
  61.   // You can call Receive(-1) to retrieve a message from any source, or with
  62.   // source in [0 .. NumberOfNodes()-1] to retrieve a message from a particular
  63.   // source.
  64.   //
  65.   // It returns the number of the instance which sent the message (which is equal
  66.   // to source, unless source is -1).
  67.   public static int Receive(int source) {
  68.       return 0;
  69.   }
  70.  
  71.   // Each of these methods returns and consumes one item from the buffer of the
  72.   // appropriate instance. You must call these methods in the order in which the
  73.   // elements were appended to the message (so, for instance, if the message was
  74.   // created with PutChar, PutChar, PutLL, you must call GetChar, GetChar, GetLL
  75.   // in this order).
  76.   // If you call them in different order, or you call a Get* method after
  77.   // consuming all the contents of the buffer, behaviour is undefined.
  78.   // The "Int" in GetInt is interpreted as 32 bits, regardless of whether the
  79.   // actual int type will be 32 or 64 bits.
  80.   public static char GetChar(int source) {
  81.       return 'a';
  82.   }
  83.   public static int GetInt(int source) {
  84.       return 0;
  85.   }
  86.   public static long GetLL(int source) {
  87.       return 0;
  88.   }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment