code
stringlengths
46
36.6k
language
stringclasses
9 values
AST_depth
int64
3
30
alphanumeric_fraction
float64
0.2
0.98
max_line_length
int64
13
399
avg_line_length
float64
5.08
140
num_lines
int64
7
299
original_docstring
stringlengths
8
34.8k
source
stringclasses
2 values
Client CreateClient( string firstName, string lastName, GenderType genderType, string pin, string phone, string email, Address address, ICollection<Lending> lendings);
c#
7
0.524715
43
28.333333
9
/// <summary> /// Represent the method which provide a instance of <see cref="Client"/> class with properties given as arguments. /// </summary> /// <param name="firstName">First name of the <see cref="Client"/> instance.</param> /// <param name="lastName">Last name of the <see cref="Client"/> instance.</param> /// <param name="genderType">Gender type of the <see cref="Client"/> instance.</param> /// <param name="pin">Personal Identification Number of the <see cref="Client"/> instance.</param> /// <param name="phone">Phone number of the <see cref="Client"/> instance.</param> /// <param name="email">Email address of the <see cref="Client"/> instance.</param> /// <param name="address">Address of the <see cref="Client"/> instance.</param> /// <param name="lendings">Initial collection of landings of the <see cref="Client"/> instance.</param> /// <returns>Instance of <see cref="Client"/> class.</returns>
function
fn h3ToLocalIj_coordinates_assertions(h3: H3Index) { let r = h3.get_resolution(); let ij = H3Index::experimentalH3ToLocalIj(h3, h3); assert!(ij.is_ok(), "get ij for origin"); let ijk = ij.unwrap().ijToIjk(); if r == Resolution::R0 { assert_eq!(ijk, CoordIJK::UNIT_VECS[0].0, "res 0 cell at 0,0,0"); } else if r == Resolution::R1 { let index = h3.get_index_digit(r); assert_eq!( ijk, CoordIJK::UNIT_VECS[index as usize].0, "res 1 cell at expected coordinates" ); } else if r == Resolution::R2 { // the C unit test uses an index digit of 1 here, not 2 let index = h3.get_index_digit(r); let mut expected = CoordIJK::UNIT_VECS[index as usize].0; expected._downAp7r(); expected._neighbor(h3.get_index_digit(r)); assert_eq!(ijk, expected, "res 2 cell at expected coordinates"); } else { assert!(false, "resolution supported by test function (coordinates)"); } }
rust
15
0.536871
82
43.52
25
/// Test that coordinates for an index match some simple rules about index /// digits, when using the index as its own origin. That is, that the IJ /// coordinates are in the coordinate space of the origin's base cell.
function
public class Relay extends LogicEntity { public static void register() { EntityRegistry.registry.put("logic_relay", new EntityFactory<Entity>() { @Override public Entity create(Level level, String name) { return new Relay(level, name); } }); } public Relay(Level level, String name) { super(level, name); } @Override public Map<String, Attribute<?>> getDefaultAttributes() { Map<String, Attribute<?>> attributes = new HashMap<>(); attributes.put("delay", new IntAttribute(0)); attributes.put("executorOverride", new StringAttribute("")); return attributes; } @Override public Collection<OutputDeclaration> getDeclaredOutputs() { Collection<OutputDeclaration> out = super.getDeclaredOutputs(); out.add(new OutputDeclaration() { @Override public String getName() { return "on_trigger"; } @Override public List<String> getArguements() { return Collections.emptyList(); } }); return out; } @Override public Collection<InputDeclaration> getDeclaredInputs() { return List.of(new InputDeclaration() { @Override public String getName() { return "trigger"; } @Override public List<String> getArguements() { return Collections.emptyList(); } }); } public int getDelay() { return ((IntAttribute) getAttribute("delay")).getValue(); } @Override public List<Command> compileInput(String inputName, List<Attribute<?>> args, Entity source, Entity instigator) { if (inputName.matches("trigger")) { Command function; if (getDelay() == 0) { function = new FunctionCommand(getTriggerFunction()); } else { function = new ScheduleCommand(getTriggerFunction(), getDelay(), Mode.APPEND); } TargetSelector executor = getExecutorOverride(); Command command; if (executor != null) { command = new ExecuteCommandBuilder().as(executor).run(function); } else { command = function; } return List.of(command); } return super.compileInput(inputName, args, source, instigator); } @Override public boolean compileLogic(Datapack datapack) { super.compileLogic(datapack); Function relayFunction = new Function(getTriggerFunction()); for (Command command : compileOutput("on_trigger")) { relayFunction.commands.add(command); } datapack.functions.add(relayFunction); return true; } public TargetSelector getExecutorOverride() { String string = (String) getAttribute("executorOverride").getValue(); return string.length() > 0 ? TargetSelector.fromString(string) : null; } public Identifier getTriggerFunction() { return LogicUtils.getEntityFunction(this, "trigger"); } @Override public String getSprite() { return "scaffold:textures/editor/relay.png"; } @Override public SDoc getDocumentation() { return SDoc.loadAsset(getAssetManager(), "doc/logic_relay.sdoc", super.getDocumentation()); } }
java
15
0.671096
113
23.965517
116
/** * This class relays io from it's inputs to it's outputs * * @author Igrium */
class
def summary(self, hyperparams=False, G_attrs=False, plot=False, **plot_kwargs): summary_dict = {attr_name: getattr(self, attr_name) for attr_name in SUMMARY_ATTRS} summary_series_list = [pd.Series(summary_dict)] if hyperparams: summary_series_list.append(pd.Series(self.hyperparams)) if G_attrs: summary_series_list.append(pd.Series(self.G_attrs)) print(pd.concat(summary_series_list)) if plot: self.plot_trends(hyperparams=hyperparams, G_attrs=G_attrs, **plot_kwargs)
python
11
0.707843
87
50.1
10
Print several summary stats, and potentially plot the trends.
function
@Experimental public class RemoveQueueBundler extends BaseBundler { protected RingBuffer<Message> rb; protected Runner runner; protected Message[] remove_queue; protected final AverageMinMax avg_batch_size=new AverageMinMax(); protected int queue_size=1024; @ManagedAttribute(description="Remove queue size") public int rqbRemoveQueueSize() {return remove_queue.length;} @ManagedAttribute(description="Sets the size of the remove queue; creates a new remove queue") public void rqbRemoveQueueSize(int size) { if(size == queue_size) return; queue_size=size; remove_queue=new Message[queue_size]; } @ManagedAttribute(description="Average batch length") public String rqbAvgBatchSize() {return avg_batch_size.toString();} @ManagedAttribute(description="Current number of messages (to be sent) in the ring buffer") public int rqbRingBufferSize() {return rb.size();} public Map<String,Object> getStats() { Map<String,Object> map=new HashMap<>(); map.put("avg-batch-size", avg_batch_size.toString()); map.put("ring-buffer-size", rb.size()); map.put("remove-queue-size", queue_size); return map; } public void resetStats() { avg_batch_size.clear(); } public void init(TP transport) { super.init(transport); rb=new RingBuffer(Message.class, transport.getBundlerCapacity()); remove_queue=new Message[queue_size]; runner=new Runner(new DefaultThreadFactory("aqb", true, true), "runner", this::run, null); } public synchronized void start() { super.start(); runner.start(); } public synchronized void stop() { runner.stop(); super.stop(); } public void send(Message msg) throws Exception { rb.put(msg); } public void run() { try { int drained=rb.drainToBlocking(remove_queue); if(drained == 1) { output.position(0); sendSingleMessage(remove_queue[0]); return; } for(int i=0; i < drained; i++) { Message msg=remove_queue[i]; int size=msg.size(); if(count + size >= transport.getMaxBundleSize()) sendBundledMessages(); addMessage(msg, msg.size()); } sendBundledMessages(); } catch(Throwable t) { } } public int getQueueSize() { return rb.size(); } public int size() { return rb.size(); } protected void sendMessageList(Address dest, Address src, List<Message> list) { super.sendMessageList(dest, src, list); avg_batch_size.add(list.size()); } }
java
14
0.587224
98
29.319149
94
/** * Bundler implementation which sends message batches (or single messages) as soon as the remove queue is full * (or max_bundler_size would be exceeded).<br/> * Messages are removed from the main queue and processed as follows (assuming they all fit into the remove queue):<br/> * A B B C C A causes the following sends: {AA} -> {CC} -> {BB}<br/> * Note that <em>null</em> is also a valid destination (send-to-all).<br/> * Contrary to {@link TransferQueueBundler}, this bundler uses a {@link RingBuffer} rather than an ArrayBlockingQueue * and the size of the remove queue is fixed. TransferQueueBundler increases the size of the remove queue * dynamically, which leads to higher latency if the remove queue grows too much. * <br/> * JIRA: https://issues.jboss.org/browse/JGRP-2171 * @author Bela Ban * @since 4.0.4 */
class
func (f *Field) Check() error { for _, sample := range f.Samples { if err := checkPattern(f.Pattern, sample); err != nil { return errors.WithStack(err) } } return nil }
go
11
0.629213
57
21.375
8
// Check returns an error if the field's pattern does not match the samples.
function
def _evaluate_SplatStructInstance( self, expr: ast.SplatStructInstance, bindings: Bindings, type_context: Optional[ConcreteType] ) -> Value: named_tuple = self._evaluate(expr.splatted, bindings) struct = self._evaluate_to_struct(expr.struct, bindings) for k, v in expr.members: new_value = self._evaluate(v, bindings) i = struct.member_names.index(k) current_type = concrete_type_from_value(named_tuple.tuple_members[i]) new_type = concrete_type_from_value(new_value) if new_type != current_type: raise EvaluateError( v.span, f'type error found at interpreter runtime! struct member {k} changing from type {current_type} to {new_type}' ) named_tuple = named_tuple.tuple_replace(i, new_value) assert isinstance(named_tuple, Value), named_tuple return named_tuple
python
12
0.659526
121
41.285714
21
Evaluates a 'splat' struct instance AST node to a value.
function
public abstract class UiTransferMsg : UiThreadMsg { public KfsShare Share; public UiTransferMsg(KfsShare share) { Share = share; } }
c#
8
0.565217
49
22.125
8
/// <summary> /// Represent a message sent by a transfer thread. /// </summary>
class
public void validateRound3PayloadReceived(JPAKERound3Payload round3PayloadReceived, BigInteger keyingMaterial) throws CryptoException { if (this.state >= STATE_ROUND_3_VALIDATED) { throw new IllegalStateException("Validation already attempted for round3 payload for" + participantId); } if (this.state < STATE_KEY_CALCULATED) { throw new IllegalStateException("Keying material must be calculated validated prior to validating Round3 payload for " + this.participantId); } JPAKEUtil.validateParticipantIdsDiffer(participantId, round3PayloadReceived.getParticipantId()); JPAKEUtil.validateParticipantIdsEqual(this.partnerParticipantId, round3PayloadReceived.getParticipantId()); JPAKEUtil.validateMacTag( this.participantId, this.partnerParticipantId, this.gx1, this.gx2, this.gx3, this.gx4, keyingMaterial, this.digest, round3PayloadReceived.getMacTag()); /* * Clear the rest of the fields. */ this.gx1 = null; this.gx2 = null; this.gx3 = null; this.gx4 = null; this.state = STATE_ROUND_3_VALIDATED; }
java
10
0.63297
153
39.21875
32
/** * Validates the payload received from the other participant during round 3. * <p> * See {@link JPAKEParticipant} for more details on round 3. * <p> * After execution, the {@link #getState() state} will be {@link #STATE_ROUND_3_VALIDATED}. * * @param round3PayloadReceived The round 3 payload received from the other participant. * @param keyingMaterial The keying material as returned from {@link #calculateKeyingMaterial()}. * @throws CryptoException if validation fails. * @throws IllegalStateException if called prior to {@link #calculateKeyingMaterial()}, or multiple times */
function
public void DrawBanner(Rage.Graphics g) { if (!Visible || _customBanner == null) return; var origRes = Game.Resolution; float aspectRaidou = origRes.Width / (float)origRes.Height; Point bannerPos = new Point(_offset.X + safezoneOffset.X, _offset.Y + safezoneOffset.Y); Size bannerSize = new Size(431 + WidthOffset, 107); PointF pos = new PointF(bannerPos.X / (1080 * aspectRaidou), bannerPos.Y / 1080f); SizeF siz = new SizeF(bannerSize.Width / (1080 * aspectRaidou), bannerSize.Height / 1080f); g.DrawTexture(_customBanner, pos.X * Game.Resolution.Width, pos.Y * Game.Resolution.Height, siz.Width * Game.Resolution.Width, siz.Height * Game.Resolution.Height); }
c#
14
0.636951
176
69.454545
11
/// <summary> /// Draw your custom banner. /// <para> /// To prevent flickering call it inside a <see cref="Game.RawFrameRender"/> event handler. /// </para> /// </summary> /// <param name="g">The <see cref="Rage.Graphics"/> to draw on.</param>
function
public class ErrorHandlerThrowException : IErrorHandler, IResponseHandler { private readonly IResponseParser _errorParser; public ErrorResponseInfo ErrorInfo { get; private set; } private bool _hasError; public ErrorHandlerThrowException(IResponseParser errorParser) { _errorParser = errorParser; } public bool HasError() { return _hasError; } public bool Handle(IParameters parameters, string response) { _hasError = false; if (_errorParser.CanParse(parameters)) { ErrorInfo = _errorParser.Parse(response) as ErrorResponseInfo; if (ErrorInfo?.Code > 0) { _hasError = true; throw new RandomOrgException(ErrorInfo.Code, ErrorInfo.Message); } } return true; } public bool CanHandle(IParameters parameters) { return true; } }
c#
14
0.545714
84
31.84375
32
/// <summary> /// Error handler which throws an exception when an error occurs /// </summary>
class
public static double CrossProductLength(double Ax, double Ay, double Bx, double By, double Cx, double Cy) { double BAx = Ax - Bx; double BAy = Ay - By; double BCx = Cx - Bx; double BCy = Cy - By; return (BAx * BCy - BAy * BCx); }
c#
9
0.485804
61
34.333333
9
/// <summary> /// Return the cross product AB x BC. /// The cross product is a vector perpendicular to AB /// and BC having length |AB| * |BC| * Sin(theta) and /// with direction given by the right-hand rule. /// For two vectors in the X-Y plane, the result is a /// vector with X and Y components 0 so the Z component /// gives the vector's length and direction. /// </summary> /// <param name="Ax"></param> /// <param name="Ay"></param> /// <param name="Bx"></param> /// <param name="By"></param> /// <param name="Cx"></param> /// <param name="Cy"></param> /// <returns></returns>
function
public static MechanismTypes ToTypeFromString(string type) { switch (type) { case "PLAIN": return MechanismTypes.Plain; case "DIGEST-MD5": return MechanismTypes.DigestMd5; case "EXTERNAL": return MechanismTypes.External; case "SCRAM-SHA-1": return MechanismTypes.Scram; case "SCRAM-SHA-1-PLUS": return MechanismTypes.ScramPlus; default: return MechanismTypes.None; } }
c#
9
0.460692
58
34.388889
18
/// <summary> /// Convert a mechanism to its type format /// </summary> /// <param name="type">String type of the mechanism</param> /// <returns>Type of the mechanism</returns>
function