git reimport

This commit is contained in:
2019-03-15 13:47:54 +04:00
commit 3b461f73de
489 changed files with 1631603 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
// The contestant-available API for the Zeus distributed contest.
#ifndef MESSAGE_H_ // NOLINT
#define MESSAGE_H_ // NOLINT
#ifdef __cplusplus
extern "C" {
#endif
// The number of nodes on which the solution is running.
int NumberOfNodes();
// The number (in the range [0 .. NumberOfNodes()-1]) of the node on which this
// process is running.
int MyNodeId();
// In all the methods below, if "target" or "source" is not in the valid range,
// the behaviour is undefined.
// The library internally has a message buffer for each of the nodes in
// [0 .. NumberOfNodes()-1]. It accumulates the message in such a buffer through
// the "Put" methods.
// Append "value" to the message that is being prepared for the node with id
// "target".
void PutChar(int target, char value);
void PutInt(int target, int value);
void PutLL(int target, long long value); // NOLINT
// Sends the message that was accumulated in the appropriate buffer to the
// "target" instance, and clear the buffer for this instance.
//
// This method is non-blocking - that is, it does not wait for the receiver to
// call "Receive", it returns immediately after sending the message.
void Send(int target);
// The library also has a receiving buffer for each instance. When you call
// "Receive" and retrieve a message from an instance, the buffer tied to this
// instance is overwritten. You can then retrieve individual parts of the
// message through the Get* methods. You must retrieve the contents of the
// message in the order in which they were appended.
//
// This method is blocking - if there is no message to receive, it will wait for
// the message to arrive.
//
// You can call Receive(-1) to retrieve a message from any source, or with with
// source in [0 .. NumberOfNodes()-1] to retrieve a message from a particular
// source.
//
// It returns the number of the instance which sent the message (which is equal
// to source, unless source is -1).
int Receive(int source);
// Each of these methods returns and consumes one item from the buffer of the
// appropriate instance. You must call these methods in the order in which the
// elements were appended to the message (so, for instance, if the message was
// created with PutChar, PutChar, PutLL, you must call GetChar, GetChar, GetLL
// in this order).
// If you call them in different order, or you call a Get* method after
// consuming all the contents of the buffer, behaviour is undefined.
char GetChar(int source);
int GetInt(int source);
long long GetLL(int source); // NOLINT
#ifdef __cplusplus
}
#endif
#endif // MESSAGE_H_ // NOLINT

72
dcj/tool/includes/zeus.h Normal file
View File

@@ -0,0 +1,72 @@
// Copyright (c) 2014, Onufry Wojtaszczuk <onufryw@gmail.com>
#ifndef RECRUITING_DISTRIBUTED_API_ZEUS_H_
#define RECRUITING_DISTRIBUTED_API_ZEUS_H_
#ifdef __cplusplus
extern "C" {
#endif
#define ZEUS(s) zeus_##s
// The basic contestant-available API for the Zeus distributed contest.
// The number of nodes on which the solution is running.
int ZEUS(NumberOfNodes)();
// The number (in the range [0 .. NumberOfNodes()-1]) of the node on which this
// process is running.
typedef int ZEUS(NodeId);
ZEUS(NodeId) ZEUS(MyNodeId());
// It is guaranteed that messages sent between two given nodes will arrive in
// order.
// No ordering guarantees are given between messages to different nodes (in
// particular, if A sends a message to B, then to C, and C sends a message to B
// after receiving the message from A, it is possible for B to receive C's
// message first).
// Send |bytes| bytes of |message| to node |target|. This is asynchronous (that
// is, it does not wait for the receiver to Receive the message).
// If |message| is shorter than |bytes|, behaviour is undefined.
// If |target| is not a valid node id (not in [0 .. NumberOfNodes()-1]), will
// crash.
void ZEUS(Send)(ZEUS(NodeId) target, const char *message, int bytes);
typedef struct {
// Id of the sending node.
ZEUS(NodeId) sender_id;
// Length of the received message in bytes.
int length;
} ZEUS(MessageInfo);
// Receive a message from the |source| node id, and copy the contents of the
// message to |buffer|, up to |buffer_size| bytes. No extra characters (in
// particular, a trailing '\0') will be appended to the message.
// A special case is |source| equal to -1, in which case a message from any
// other node can be received.
// This call is blocking - that is, the function will not return until a message
// is received.
// A std::pair will be returned.
// First element of the pair will be the id of the sending node.
// Second element of the pair will be the length of the received message
// in bytes.
//
// If the received message is larger than |buffer_size|, will crash.
// If the received message is smaller than |buffer_size|, the rest of the buffer
// contents are not modified.
// If |buffer| is smaller than |buffer_size|, behaviour is undefined.
// If |source| is neither -1 nor a valid node ID, will crash.
ZEUS(MessageInfo) ZEUS(Receive)(ZEUS(NodeId) source, char *buffer, int buffer_size);
// Returns the list of nodes from which we have unreceived messages (thus,
// calling Receive() with one of the returned node ids as the argument will
// not block). The order in which the node IDs are given is not specified. Each
// ID will be given once.
//std::vector<NodeId> Poll(); // NOTE: NOT IMPLEMENTED
#ifdef __cplusplus
}
#endif
#endif // RECRUITING_DISTRIBUTED_API_ZEUS_H_