blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 2
247
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 4
111
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringlengths 4
58
| visit_date
timestamp[ns]date 2015-07-25 18:16:41
2023-09-06 10:45:08
| revision_date
timestamp[ns]date 1970-01-14 14:03:36
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 1970-01-14 14:03:36
2023-09-06 06:22:19
| github_id
int64 3.89k
689M
⌀ | star_events_count
int64 0
209k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 25
values | gha_event_created_at
timestamp[ns]date 2012-06-07 00:51:45
2023-09-14 21:58:52
⌀ | gha_created_at
timestamp[ns]date 2008-03-27 23:40:48
2023-08-24 19:49:39
⌀ | gha_language
stringclasses 159
values | src_encoding
stringclasses 34
values | language
stringclasses 1
value | is_vendor
bool 1
class | is_generated
bool 2
classes | length_bytes
int64 7
10.5M
| extension
stringclasses 111
values | filename
stringlengths 1
195
| text
stringlengths 7
10.5M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
de1ed43d9644c7958abc9cabc4e4bb292e868ef7
|
34c8fbdf8808159fd4a1447b7e5263c10d1a2122
|
/Visual Studio 2012/Projects/final/Fighter.cpp
|
921d7afa61ab91bba55747733a7dbbd9386d1131
|
[] |
no_license
|
cjpwrs/Cplusplus-Projects
|
35759c304577c6938d99aeb3c224efb2a7d35823
|
d5fbda0dbf9b2718c8ecb8b4e7d2563b24a8296f
|
refs/heads/master
| 2021-01-10T13:07:07.704098
| 2015-10-02T03:07:41
| 2015-10-02T03:07:41
| 43,533,430
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,000
|
cpp
|
Fighter.cpp
|
#include "Fighter.h"
#include <vector>
#include<sstream>
Fighter::Fighter(string name, int hp, int strength, int magic)
{
}
Fighter::~Fighter(void){}
/*Fighter::Fighter(string name, int hp, int speed, int magic)
{
}*/
/*
* getName()
*
* Returns the name of this fighter.
*/
string Fighter::getName()
{
return name;
}
/*
* getMaximumHP()
*
* Returns the maximum hit points of this fighter.
*/
int Fighter::getMaximumHP()
{
return max_hp;
}
/*
* getCurrentHP()
*
* Returns the current hit points of this fighter.
*/
int Fighter::getCurrentHP()
{
return current_hp;
}
/*
* getStrength()
*
* Returns the strength stat of this fighter.
*/
int Fighter::getStrength()
{
return strength;
}
/*
* getSpeed()
*
* Returns the speed stat of this fighter.
*/
int Fighter::getSpeed()
{
return speed;
}
/*
* getMagic()
*
* Returns the magic stat of this fighter.
*/
int Fighter::getMagic()
{
return magic;
}
/*
* getDamage()
*
* Returns the amount of damage a fighter will deal.
*
* Robot:
* This value is equal to the Robot's strength plus any additional damage added for having just used its special ability.
*
* Archer:
* This value is equal to the Archer's speed.
*
* Cleric:
* This value is equal to the Cleric's magic.
*/
int Fighter::getDamage()
{
}
/*
* takeDamage(int)
*
* Reduces the fighter's current hit points by an amount equal to the given
* damage minus one fourth of the fighter's speed (minimum of one). It is
* acceptable for this method to give the fighter negative current hit points.
*
* Examples:
* damage=10, speed=3 => damage_taken=10
* damage=10, speed=7 => damage_taken=9
* damage=10, speed=9 => damage_taken=8
* damage=10, speed=50 => damage_taken=1
*/
void takeDamage(int damage)
{
int damage_taken = 0 ;
damage_taken = damage - (speed/4) ;
if (damage_taken >= 1)
{
current_hp = current_hp - damage_taken ;
}
else if (damage_taken == 0)
{
current_hp-- ;
}
}
/*
* reset()
*
* Restores a fighter's current hit points to its maximum value.
*
* Robot:
* Also restores a Robot's current electricity to its maximum value.
* Also resets a Robot's bonus damage to 0.
*
* Archer:
* Also resets an Archer's speed to its original value.
*
* Cleric:
* Also restores a Cleric's current mana to its maximum value.
*/
void Fighter::reset()
{
}
/*
* regenerate()
*
* Increases the fighter's current hit points by an amount equal to one sixth of
* the fighter's strength (minimum of one unless already at maximum).
*
* Cleric:
* Also increases a Cleric's current mana by an amount equal to one fifth of the
* Cleric's magic (minimum of one unless already at maximum).
*/
void Fighter::regenerate()
{
}
/*
* useAbility()
*
* Attempts to perform a special ability based on the type of fighter. The
* fighter will attempt to use this special ability just prior to attacking
* every turn.
*
* Robot: Shockwave Punch
* Adds bonus damage to the Robot's next attack (and only its next attack) equal to (strength * ((current_electricity/maximum_electricity)^4)).
* Can only be used if the Robot has at least [ROBOT_ABILITY_COST] electricity.
* Decreases the Robot's current electricity by [ROBOT_ABILITY_COST] (after calculating the additional damage) when used.
* The bonus damage formula should be computed using double arithmetic, and only the final result should be cast into an integer.
* Examples:
* strength=20, current_electricity=20, maximum_electricity=20 => bonus_damage=20
* strength=20, current_electricity=15, maximum_electricity=20 => bonus_damage=6
* strength=20, current_electricity=10, maximum_electricity=20 => bonus_damage=1
* strength=20, current_electricity=5, maximum_electricity=20 => bonus_damage=0
*
* Archer: Quickstep
* Increases the Archer's speed by one point each time the ability is used.
* This bonus lasts until the reset() method is used.
* This ability always works; there is no maximum bonus speed.
*
* Cleric: Healing Light
* Increases the Cleric's current hit points by an amount equal to one third of its magic (minimum of one unless already at maximum).
* Can only be used if the Cleric has at least [CLERIC_ABILITY_COST] mana.
* Will be used even if the Cleric's current hit points is equal to their maximum hit points.
* Decreases the Cleric's current mana by [CLERIC_ABILITY_COST] when used.
*
* Return true if the ability was used; false otherwise.
*/
bool Fighter::useAbility()
{
}
|
799bbf4fa3ad7e932b725d794734f81ee82a638e
|
5178ebecc4458b360b7593e31353ab18e519953e
|
/src/npstat-4.9.0/examples/C++/lorpe_multivariate.cc
|
7204c7c8c8589496fda782b3a9f4e529813e7516
|
[
"MIT"
] |
permissive
|
KanZhang23/Tmass
|
9ee2baff245a1842e3ceaaa04eb8f5fb923faea9
|
6cf430a7a8e717874298d99977cb50c8943bb1b9
|
refs/heads/master
| 2022-01-10T10:51:49.627777
| 2019-06-12T14:53:17
| 2019-06-12T14:53:17
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,797
|
cc
|
lorpe_multivariate.cc
|
// The following program illustrates multivariate LOrPE usage.
// It generates a set of multivariate Gaussian random numbers
// and then reconstructs the distribution using LOrPE.
#include <tr1/array>
#include "npstat/nm/BoxNDScanner.hh"
#include "npstat/nm/rectangleQuadrature.hh"
#include "npstat/rng/MersenneTwister.hh"
#include "npstat/stat/DistributionsND.hh"
#include "npstat/stat/ScalableGaussND.hh"
#include "npstat/stat/LocalPolyFilterND.hh"
#include "npstat/stat/HistoND.hh"
#include "npstat/stat/scanDensityAsWeight.hh"
using namespace npstat;
int main(int, char**)
{
// Some simple program configuration parameters.
// They are hardwired here -- of course, one can also
// write some parsing code so that these parameters
// are picked up from the command line.
// Dimensionality of the sample
const unsigned DIM = 2;
// Parameters of the multivariate Gaussian distribution
const double gaussian_mean[DIM] = {0.0, 0.5};
const double gaussian_sigma[DIM] = {1.0, 1.5};
const unsigned sample_points = 400;
// Parameters of the data discretization grid. Note that the grid
// chosen here effectively chops off a fraction of the distribution
// in order to illustrate the boundary effects.
const double interval_min[DIM] = {0.0, 0.0};
const double interval_max[DIM] = {10.0, 10.0};
const unsigned grid_points[DIM] = {100, 100};
// Grid cell size in each dimension
double grid_step[DIM];
for (unsigned i=0; i<DIM; ++i)
grid_step[i] = (interval_max[i] - interval_min[i])/grid_points[i];
// Choose LOrPE kernel. For subsequent use with "scanDensityAsWeight"
// function, kernel should be centered at the origin and have unit
// width in each dimension.
const double kernel_location[DIM] = {0., 0.}, kernel_width[DIM] = {1., 1.};
const AbsDistributionND* kernel = new ScalableSymmetricBetaND(
kernel_location, kernel_width, DIM, 4);
// Degree of the LOrPE filter
const unsigned lorpe_degree = 2;
// Bandwidth of the LOrPE filter
const double lorpe_bandwidth[DIM] = {3.0, 4.0};
// In this example we will use the simplest LOrPE filter
// which does not have a taper function. There is instead
// the maximum degree of the polynomial.
//
// First, create the table of kernel values. We will need
// to scan one quadrant only.
//
CPP11_auto_ptr<ArrayND<double> > kernelScan = scanDensityAsWeight(
*kernel, grid_points, lorpe_bandwidth, grid_step, DIM, true);
// Now, create the LOrPE filter
ArrayShape dataShape(grid_points, grid_points+DIM);
LocalPolyFilterND<lorpe_degree> lorpeFilter(
0, lorpe_degree, *kernelScan, dataShape);
// Create the random number generator. The default constructor of
// MersenneTwister will pick the generator seed from /dev/urandom.
MersenneTwister rng;
// Come up with the sequence of generated points
// (this is our pseudo-data)
std::vector<std::tr1::array<double,DIM> > points;
points.reserve(sample_points);
ScalableGaussND gauss(gaussian_mean, gaussian_sigma, DIM);
for (unsigned i=0; i<sample_points; ++i)
{
std::tr1::array<double,DIM> r;
gauss.random(rng, &r[0], DIM);
points.push_back(r);
}
// Discretize the sequence on a grid. We will use a histogram
// to represent the discretized empirical density.
std::vector<HistoAxis> axes;
for (unsigned i=0; i<DIM; ++i)
axes.push_back(HistoAxis(grid_points[i], interval_min[i], interval_max[i]));
HistoND<double> sampleHistogram(axes);
for (unsigned i=0; i<sample_points; ++i)
sampleHistogram.fill(&points[i][0], DIM, 1.0);
// Filter the histogrammed sample. The result is written into
// an array object. This is our reconstructed density.
ArrayND<double> reconstructed(dataShape);
lorpeFilter.filter(sampleHistogram.binContents(), &reconstructed);
// Chop off negative values of the reconstructed density
reconstructed.makeNonNegative();
// Normalize reconstructed density so that its integral is 1
const double cell_size = sampleHistogram.binVolume();
const double lorpeIntegral = reconstructed.sum<long double>()*cell_size;
assert(lorpeIntegral > 0.0);
reconstructed /= lorpeIntegral;
// Calculate the ISE for this sample. For this, we need to
// discretize the actual distribution according to which
// the random points were generated. The distribution density
// will be integrated across each discretization grid cell
// using Gauss-Legendre quadrature.
BoxND<double> scanbox;
for (unsigned i=0; i<DIM; ++i)
scanbox.push_back(Interval<double>(interval_min[i], interval_max[i]));
ArrayND<double> original(dataShape);
DensityFunctorND gaussFcn(gauss);
double coords[DIM];
for (BoxNDScanner<double> scanner(scanbox,dataShape);
scanner.isValid(); ++scanner)
{
scanner.getCoords(coords, DIM);
original.linearValue(scanner.state()) = rectangleIntegralCenterAndSize(
gaussFcn, coords, grid_step, DIM, 4);
}
// Normalize the original density inside the grid interval to 1
const double normalizationIntegral = original.sum<long double>()*cell_size;
assert(normalizationIntegral > 0.0);
original /= normalizationIntegral;
// The actual ISE calculation
const double ise = (reconstructed - original).sumsq<long double>()*cell_size;
// Print the ISE value to the standard output
std::cout << "LOrPE ISE for the current mutivariate random sample is "
<< ise << std::endl;
// Some cleanup (release memory allocated inside this program)
delete kernel;
// We are done
return 0;
}
|
9c831443317261398badd0975f0c8843d30fe775
|
ab0a8234e443a6aa152b9f7b135a1e2560e9db33
|
/Server/CGSF/BaseLayer/CPUDesc.h
|
7bf86d5a434f961a389d809e4d76393e4277de21
|
[] |
no_license
|
zetarus/Americano
|
71c358d8d12b144c8858983c23d9236f7d0e941b
|
b62466329cf6f515661ef9fb9b9d2ae90a032a60
|
refs/heads/master
| 2023-04-08T04:26:29.043048
| 2018-04-19T11:21:14
| 2018-04-19T11:21:14
| 104,159,178
| 9
| 2
| null | 2023-03-23T12:10:51
| 2017-09-20T03:11:44
|
C++
|
UTF-8
|
C++
| false
| false
| 2,201
|
h
|
CPUDesc.h
|
#pragma once
class CPUInfo;
typedef struct tagProcessorInfo
{
DWORD dwProcessorIndex;
// Serial Number
char szSerialNumber[128];
// On-Chip Hardware Features
BOOL bAPICPresent;
int APICID;
BOOL bACPICapable;
BOOL bOnChipThermalMonitor;
BOOL bL1Cache;
int L1CacheSize;
BOOL bL2Cache;
int L2CacheSize;
BOOL bL3Cache;
int L3CacheSize;
//Power Management Features
BOOL bTemperatureSensingDiode;
BOOL bFrequencyIDControl;
BOOL bVoltageIDControl;
//Supported Features
BOOL bCMOVInstructions;
BOOL bMTRRInstructions;
BOOL bMMXInstructions;
BOOL bMMXPlusInstructions;
BOOL bSSEInstructions;
BOOL bSSEFPInstructions;
BOOL bSSEMMXInstructions;
BOOL bSSE2Instructions;
BOOL bAMD3DNowInstructions;
BOOL bAMD3DNowPlusInstructions;
BOOL bHyperthreadingInstructions;
int LogicalProcessorsPerPhysical;
BOOL bMultiprocessorCapable;
BOOL bIA64Instructions;
tagProcessorInfo()
{
dwProcessorIndex = 0;
memset(this, 0, sizeof(PROCESSORINFO));
}
} PROCESSORINFO, *PPROCESSORINFO;
class CCPUDesc
{
friend class SFSystemInfo;
public:
CCPUDesc(void);
virtual ~CCPUDesc(void);
char* GetVendorID();
char* GetTypeID();
char* GetFamilyID();
char* GetModelID();
char* GetSteppingCode();
char* GetExtendedProcessorName();
int GetProcessorClockFrequency();
int GetProcessorNum(){return m_dwProcessorsNum;}
bool IsSupportCPUID(){return m_bSupportCPUID;}
PPROCESSORINFO GetProcessorsInfo(){return m_aDetailProcessorInfo;}
DWORD GetL1CacheSize(){return m_processorL1CacheSize;}
DWORD GetL2CacheSize(){return m_processorL2CacheSize;}
DWORD GetL3CacheSize(){return m_processorL3CacheSize;}
BOOL ProcessGetDetailedProcessInfo();
BOOL ProcessGetCacheInfo();
protected:
BOOL Initialize();
private:
bool m_bSupportCPUID;
DWORD m_dwProcessorsNum;
CPUInfo* m_pCPUInfo;
PPROCESSORINFO m_aDetailProcessorInfo;
//Cache
DWORD m_logicalProcessorCount;
DWORD m_numaNodeCount;
DWORD m_processorCoreCount;
DWORD m_processorL1CacheCount;
DWORD m_processorL2CacheCount;
DWORD m_processorL3CacheCount;
DWORD m_processorPackageCount;
DWORD m_processorL1CacheSize;
DWORD m_processorL2CacheSize;
DWORD m_processorL3CacheSize;
};
|
f9040d762f0db3f3bd834d14d7c812dfc5fd752c
|
6ff6338d11c8659055d8709450c979be2cc3fc2c
|
/src/core/cv/include/s3d/cv/image_operation/input_output_adapter.h
|
b597922c81546126c2e48227e6ae92ada3c75358
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
introlab/OpenS3D
|
80e6a6b50743852a1b139fe241d76ce575a8154e
|
dad9ef18ce78e99b8a29c934f09d1eb12f1b6a66
|
refs/heads/master
| 2019-07-08T01:43:16.502294
| 2018-03-21T12:23:45
| 2018-03-21T12:23:45
| 88,108,814
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 890
|
h
|
input_output_adapter.h
|
#ifndef S3D_CV_IMAGE_OPERATION_INPUT_OUTPUT_ADAPTER_H
#define S3D_CV_IMAGE_OPERATION_INPUT_OUTPUT_ADAPTER_H
#include <s3d/multiview/stan_results.h>
#include <opencv2/core/mat.hpp>
#include <gsl/gsl>
namespace s3d {
namespace image_operation {
class ImageOperations;
class InputOutputAdapter {
public:
InputOutputAdapter(gsl::not_null<ImageOperations*> imageOperations);
void setInputImages(const cv::Mat& leftImage, const cv::Mat& rightImage);
std::tuple<cv::Mat&, cv::Mat&> getOutputImages();
bool applyAllOperations();
void copyInputToOutputs();
bool canApplyOperations();
StanResults results;
private:
cv::Mat inputLeftImage{};
cv::Mat inputRightImage{};
cv::Mat outputLeftImage{};
cv::Mat outputRightImage{};
ImageOperations* operations_{};
};
} // namespace s3d
} // namespace image_operation
#endif // S3D_CV_IMAGE_OPERATION_INPUT_OUTPUT_ADAPTER_H
|
9adfe735ad19f19b7abf77f5c3cab01c3b168b9c
|
95ade71b4d0e315abb0ffe6263db7e1eecef7146
|
/apps/sssp/sssp_outer.cc
|
7b643a6d06c84d590115bcd6dc1e70ead5fdff02
|
[
"MIT"
] |
permissive
|
masabahmad/CRONO
|
884da229b4c4e9928b76d182a94e5b6d89ae77f8
|
244d54823edb841ee11673174b4d5976bd3ace53
|
refs/heads/master
| 2022-07-27T13:22:32.960356
| 2022-07-18T15:09:38
| 2022-07-18T15:09:38
| 40,583,630
| 34
| 22
|
MIT
| 2022-07-18T15:09:39
| 2015-08-12T06:17:10
|
C++
|
UTF-8
|
C++
| false
| false
| 13,688
|
cc
|
sssp_outer.cc
|
/*
Distributed Under the MIT license
Uses the Bellman-Ford/Dijkstra Algorithm to find shortest path distances
Programs by Masab Ahmad (UConn)
*/
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
//#include "carbon_user.h" /*For the Graphite Simulator*/
#include <time.h>
#include <sys/timeb.h>
#define MAX 100000000
#define INT_MAX 100000000
#define BILLION 1E9
//Thread Argument Structure
typedef struct
{
int* local_min;
int* global_min;
int* Q;
int* D;
int* D_temp;
int** W;
int** W_index;
int* d_count;
int tid;
int P;
int N;
int DEG;
pthread_barrier_t* barrier;
} thread_arg_t;
//Function Initializers
int initialize_single_source(int* D, int* D_temp, int* Q, int source, int N);
void relax(int u, int i, volatile int* D, int** W, int** W_index, int N);
int get_local_min(volatile int* Q, volatile int* D, int start, int stop, int N, int** W_index, int** W, int u);
void init_weights(int N, int DEG, int** W, int** W_index);
//Global Variables
int min = INT_MAX;
int min_index = 0;
pthread_mutex_t lock;
pthread_mutex_t locks[2097152]; //change the number of locks to approx or greater N
int u = -1;
int local_min_buffer[1024];
int global_min_buffer;
int terminate = 0;
int cntr = 0;
int *exist;
int *id;
int P_max=64;
double largest_d;
thread_arg_t thread_arg[1024];
pthread_t thread_handle[1024];
//Primary Parallel Function
void* do_work(void* args)
{
volatile thread_arg_t* arg = (thread_arg_t*) args;
int tid = arg->tid; //thread id
int P = arg->P; //Max threads
int* D_temp = arg->D_temp; //Temporary Distance Array
int* D = arg->D; //distabces
int** W = arg->W; //edge weights
int** W_index = arg->W_index; //graph structure
const int N = arg->N; //Max vertices
const int DEG = arg->DEG; //edges per vertex
int v = 0;
int cntr_0 = 0;
int start = 0;
int stop = 1;
int neighbor=0;
//For precision dynamic work allocation
double P_d = P;
//double range_d = 1.0;
double tid_d = tid;
double start_d = (tid_d) * (largest_d/P_d);
double stop_d = (tid_d+1.0) * (largest_d/P_d);
start = start_d;//tid * (largest+1) / (P);
stop = stop_d;//(tid+1) * (largest+1) / (P);
//printf("\n %d %d %d",tid,start,stop);
pthread_barrier_wait(arg->barrier);
while(terminate==0)
{
//printf("\n Start:%d",tid);
for(v=start;v<stop;v++)
{
D[v] = D_temp[v];
}
pthread_barrier_wait(arg->barrier);
terminate = 1;
for(v=start;v<stop;v++)
{
if(exist[v]==0)
continue;
for(int i = 0; i < DEG; i++)
{
//if(v<N)
neighbor = W_index[v][i];
if(neighbor>=N)
break;
//pthread_mutex_lock(&locks[neighbor]);
//relax
if((D[W_index[v][i]] > (D[v] + W[v][i]))) //relax, update distance
D_temp[W_index[v][i]] = D[v] + W[v][i];
//printf("\n %d",D_temp[W_index[v][i]]);
//pthread_mutex_unlock(&locks[neighbor]);
}
}
pthread_barrier_wait(arg->barrier);
for(v=start;v<stop;v++)
{
if(D[v] != D_temp[v])
{
terminate = 0;
}
}
pthread_barrier_wait(arg->barrier);
cntr_0++;
}
//printf("\n terminate %d",tid);
if(tid==0)
cntr = cntr_0;
pthread_barrier_wait(arg->barrier);
return NULL;
}
// Create a dotty graph named 'fn'.
void make_dot_graph(int **W,int **W_index,int *exist,int *D,int N,int DEG,const char *fn)
{
FILE *of = fopen(fn,"w");
if (!of) {
printf ("Unable to open output file %s.\n",fn);
exit (EXIT_FAILURE);
}
fprintf (of,"digraph D {\n"
" rankdir=LR\n"
" size=\"4,3\"\n"
" ratio=\"fill\"\n"
" edge[style=\"bold\"]\n"
" node[shape=\"circle\",style=\"filled\"]\n");
// Write out all edges.
for (int i = 0; i != N; ++i) {
if (exist[i]) {
for (int j = 0; j != DEG; ++j) {
if (W_index[i][j] != INT_MAX) {
fprintf (of,"%d -> %d [label=\"%d\"]\n",i,W_index[i][j],W[i][j]);
}
}
}
}
# ifdef DISTANCE_LABELS
// We label the vertices with a distance, if there is one.
fprintf (of,"0 [fillcolor=\"red\"]\n");
for (int i = 0; i != N; ++i) {
if (D[i] != INT_MAX) {
fprintf (of,"%d [label=\"%d (%d)\"]\n",i,i,D[i]);
}
}
# endif
fprintf (of,"}\n");
fclose (of);
}
int main(int argc, char** argv)
{
if (argc < 3) {
printf ("Usage: %s <thread-count> <input-file>\n",argv[0]);
return 1;
}
int N = 0;
int DEG = 0;
FILE *file0 = NULL;
const int select = atoi(argv[1]);
const int P = atoi(argv[2]);
if(select==0)
{
N = atoi(argv[3]);
DEG = atoi(argv[4]);
printf("\nGraph with Parameters: N:%d DEG:%d\n",N,DEG);
}
if (!P) {
printf ("Error: Thread count must be a valid integer greater than 0.");
return 1;
}
if(select==1)
{
const char *filename = argv[3];
file0 = fopen(filename,"r");
if (!file0) {
printf ("Error: Unable to open input file '%s'\n",filename);
return 1;
}
N = 2000000; //can be read from file if needed, this is a default upper limit
DEG = 16; //also can be reda from file if needed, upper limit here again
}
int lines_to_check=0;
char c;
int number0;
int number1;
int previous_node = -1;
int inter = -1;
if (DEG > N)
{
fprintf(stderr, "Degree of graph cannot be grater than number of Vertices\n");
exit(EXIT_FAILURE);
}
int* D;
int* D_temp;
int* Q;
if (posix_memalign((void**) &D, 64, N * sizeof(int)))
{
fprintf(stderr, "Allocation of memory failed\n");
exit(EXIT_FAILURE);
}
if(posix_memalign((void**) &D_temp, 64, N * sizeof(int)))
{
fprintf(stderr, "Allocation of memory failed\n");
exit(EXIT_FAILURE);
}
if( posix_memalign((void**) &Q, 64, N * sizeof(int)))
{
fprintf(stderr, "Allocation of memory failed\n");
exit(EXIT_FAILURE);
}
if( posix_memalign((void**) &exist, 64, N * sizeof(int)))
{
fprintf(stderr, "Allocation of memory failed\n");
exit(EXIT_FAILURE);
}
if(posix_memalign((void**) &id, 64, N * sizeof(int)))
{
fprintf(stderr, "Allocation of memory failed\n");
exit(EXIT_FAILURE);
}
int d_count = N;
pthread_barrier_t barrier;
int** W = (int**) malloc(N*sizeof(int*));
int** W_index = (int**) malloc(N*sizeof(int*));
for(int i = 0; i < N; i++)
{
int ret = posix_memalign((void**) &W[i], 64, DEG*sizeof(int));
int re1 = posix_memalign((void**) &W_index[i], 64, DEG*sizeof(int));
if (ret != 0 || re1!=0)
{
fprintf(stderr, "Could not allocate memory\n");
exit(EXIT_FAILURE);
}
}
for(int i=0;i<N;i++)
{
for(int j=0;j<DEG;j++)
{
W[i][j] = INT_MAX;
W_index[i][j] = INT_MAX;
}
exist[i]=0;
id[0] = 0;
}
if(select==1)
{
for(c=getc(file0); c!=EOF; c=getc(file0))
{
if(c=='\n')
lines_to_check++;
if(lines_to_check>3)
{
int f0 = fscanf(file0, "%d %d", &number0,&number1);
if(f0 != 2 && f0 != EOF)
{
printf ("Error: Read %d values, expected 2. Parsing failed.\n",f0);
exit (EXIT_FAILURE);
}
//printf("\n%d %d",number0,number1);
if (number0 >= N) {
printf ("Error: Node %d exceeds maximum graph size of %d.\n",number0,N);
exit (EXIT_FAILURE);
}
exist[number0] = 1; exist[number1] = 1;
id[number0] = number0;
if(number0==previous_node) {
inter++;
} else {
inter=0;
}
// Make sure we haven't exceeded our maximum degree.
if (inter >= DEG) {
printf ("Error: Node %d, maximum degree of %d exceeded.\n",number0,DEG);
exit (EXIT_FAILURE);
}
// We don't support parallel edges, so check for that and ignore.
bool exists = false;
for (int i = 0; i != inter; ++i) {
if (W_index[number0][i] == number1) {
exists = true;
break;
}
}
if (!exists) {
W[number0][inter] = inter+1;
W_index[number0][inter] = number1;
previous_node = number0;
}
}
} //W[2][0] = -1;
}
//Generate a uniform random graph
if(select==0)
{
init_weights(N, DEG, W, W_index);
}
//Synchronization Variables
pthread_barrier_init(&barrier, NULL, P);
pthread_mutex_init(&lock, NULL);
for(int i=0; i<N; i++)
{
pthread_mutex_init(&locks[i], NULL);
if(select==0)
exist[i]=1;
}
int largest = N;
largest_d = largest;
//Initialize data structures
initialize_single_source(D, D_temp, Q, 0, N);
//Thread Arguments
for(int j = 0; j < P; j++) {
thread_arg[j].local_min = local_min_buffer;
thread_arg[j].global_min = &global_min_buffer;
thread_arg[j].Q = Q;
thread_arg[j].D = D;
thread_arg[j].D_temp = D_temp;
thread_arg[j].W = W;
thread_arg[j].W_index = W_index;
thread_arg[j].d_count = &d_count;
thread_arg[j].tid = j;
thread_arg[j].P = P;
thread_arg[j].N = N;
thread_arg[j].DEG = DEG;
thread_arg[j].barrier = &barrier;
}
//for clock time
struct timespec requestStart, requestEnd;
clock_gettime(CLOCK_REALTIME, &requestStart);
// Enable Graphite performance and energy models
//CarbonEnableModels();
//create threads
for(int j = 1; j < P; j++) {
pthread_create(thread_handle+j,
NULL,
do_work,
(void*)&thread_arg[j]);
}
do_work((void*) &thread_arg[0]);
//join threads
for(int j = 1; j < P; j++) { //mul = mul*2;
pthread_join(thread_handle[j],NULL);
}
// Disable Graphite performance and energy models
//CarbonDisableModels();
//read clock for time
clock_gettime(CLOCK_REALTIME, &requestEnd);
double accum = ( requestEnd.tv_sec - requestStart.tv_sec ) + ( requestEnd.tv_nsec - requestStart.tv_nsec ) / BILLION;
printf( "Elapsed time: %lfs\n", accum );
//printf("\ndistance:%d \n",D[N-1]);
make_dot_graph(W,W_index,exist,D,N,DEG,"rgraph.dot");
printf("\n Iterations taken:%d",cntr);
//for distance values check
FILE * pfile;
pfile = fopen("myfile.txt","w");
fprintf (pfile,"distances:\n");
for(int i = 0; i < N; i++) {
if(D[i] != INT_MAX) {
fprintf(pfile,"distance(%d) = %d\n", i, D[i]);
}
}
fclose(pfile);
printf("\n");
return 0;
}
int initialize_single_source(int* D,
int* D_temp,
int* Q,
int source,
int N)
{
for(int i = 0; i < N; i++)
{
D[i] = INT_MAX;
D_temp[i] = INT_MAX;
Q[i] = 1;
}
D[source] = 0;
D_temp[source] = 0;
return 0;
}
int get_local_min(volatile int* Q, volatile int* D, int start, int stop, int N, int** W_index, int** W, int u)
{
int min = INT_MAX;
int min_index = N;
for(int i = start; i < stop; i++)
{
if(W_index[u][i]==-1 || W[u][i]==INT_MAX)
continue;
if(D[i] < min && Q[i])
{
min = D[i];
min_index = W_index[u][i];
}
}
return min_index;
}
void relax(int u, int i, volatile int* D, int** W, int** W_index, int N)
{
if((D[W_index[u][i]] > (D[u] + W[u][i]) && (W_index[u][i]!=-1 && W_index[u][i]<N && W[u][i]!=INT_MAX)))
D[W_index[u][i]] = D[u] + W[u][i];
}
void init_weights(int N, int DEG, int** W, int** W_index)
{
// Initialize to -1
for(int i = 0; i < N; i++)
for(int j = 0; j < DEG; j++)
W_index[i][j]= -1;
// Populate Index Array
for(int i = 0; i < N; i++)
{
int last = 0;
for(int j = 0; j < DEG; j++)
{
if(W_index[i][j] == -1)
{
int neighbor = i + j;//rand()%(max);
if(neighbor > last)
{
W_index[i][j] = neighbor;
last = W_index[i][j];
}
else
{
if(last < (N-1))
{
W_index[i][j] = (last + 1);
last = W_index[i][j];
}
}
}
else
{
last = W_index[i][j];
}
if(W_index[i][j]>=N)
{
W_index[i][j] = N-1;
}
}
}
// Populate Cost Array
for(int i = 0; i < N; i++)
{
for(int j = 0; j < DEG; j++)
{
double v = drand48();
/*if(v > 0.8 || W_index[i][j] == -1)
{ W[i][j] = MAX;
W_index[i][j] = -1;
}
else*/ if(W_index[i][j] == i)
W[i][j] = 0;
else
W[i][j] = (int) (v*100) + 1;
//printf(" %d ",W_index[i][j]);
}
//printf("\n");
}
}
|
a1bab8df0301126fb451a4d0f12b992b2ce187da
|
f9d34402f5ff9fed3baa23728f724c8250944697
|
/learncpp_com/5-flow_control/133-quiz_free_fall/src/main.cpp
|
0090f90d3edbddd227331b66812e474603e9fcb8
|
[
"MIT"
] |
permissive
|
mitsiu-carreno/cpp_tutorial
|
deb45e4c593bbceed7e33ea4fddcb6dc2023eeb5
|
71f9083884ae6aa23774c044c3d08be273b6bb8e
|
refs/heads/master
| 2021-06-27T00:25:14.031408
| 2020-10-26T17:54:22
| 2020-10-26T17:54:22
| 139,908,459
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,721
|
cpp
|
main.cpp
|
#include <iostream>
#include <cmath>
#include "constants.hpp"
bool validInput()
{
if(std::cin.fail())
{
std::cin.clear();
std::cin.ignore(32767, '\n');
return false;
}
// Clear any aditional bad input
std::cin.ignore(32767, '\n');
return true;
}
// gets initial height from user and returns it
double getInitialHeight()
{
while(true)
{
double height;
std::cout << "Enter the building height in meters: ";
std::cin >> height;
if(validInput()){
return height;
}else{
std::cout << "Sorry not a valid input man, please put a double man.\n\n";
}
}
}
// Returns height from ground after "elapsedSeconds"
double calcHeight(double initialHeight, int elapsedSeconds)
{
// Using formula: [s = u * t + (a*t^2) / 2], here u (initial velocity) = 0
double distanceFallen = (myConstants::gravity * pow(elapsedSeconds, 2) / 2);
double currentHeight = initialHeight - distanceFallen;
return currentHeight;
}
// Print height every second till ball has reached the ground
void printHeight(double initialHeight)
{
double currentHeight = initialHeight;
int elapsedSeconds = 0;
while(currentHeight > 0)
{
currentHeight = calcHeight(currentHeight, elapsedSeconds);
if(currentHeight > 0)
std::cout << "At " << elapsedSeconds << " seconds the ball is " << currentHeight << " meters high\n";
else
std::cout << "At " << elapsedSeconds << " seconds the fall is on the floor\n";
++elapsedSeconds;
}
}
int main()
{
double height;
height = getInitialHeight();
printHeight(height);
return 0;
}
|
264fd7a057128dbfcb34ba58e11a1454ae5d8b7c
|
c14500adc5ce57e216123138e8ab55c3e9310953
|
/Mesh/delaunay_refinement.h
|
3360315f727d5ce3b6f0c8462a49ec153ab8906e
|
[
"LicenseRef-scancode-warranty-disclaimer",
"LGPL-2.0-or-later",
"LicenseRef-scancode-generic-exception",
"GPL-1.0-or-later",
"LicenseRef-scancode-proprietary-license",
"GPL-2.0-only",
"GPL-2.0-or-later",
"LicenseRef-scancode-other-copyleft",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
ResonanceGroup/GMSH304
|
8c8937ed3839c9c85ab31c7dd2a37568478dc08e
|
a07a210131ee7db8c0ea5e22386270ceab44a816
|
refs/heads/master
| 2020-03-14T23:58:48.751856
| 2018-05-02T13:51:09
| 2018-05-02T13:51:09
| 131,857,142
| 0
| 1
|
MIT
| 2018-05-02T13:51:10
| 2018-05-02T13:47:05
| null |
UTF-8
|
C++
| false
| false
| 523
|
h
|
delaunay_refinement.h
|
// Gmsh - Copyright (C) 1997-2017 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _DELAUNAY_REFINEMENT_H
#define _DELAUNAY_REFINEMENT_H
#include "SPoint3.h"
#include <vector>
class Tet;
class Vert;
void delaunayRefinement (const int numThreads,
const int nptsatonce,
std::vector<Vert*> &S,
std::vector<Tet*> &T,
double (*f)(const SPoint3 &p, void *),
void *data);
#endif
|
d7f6653793702c943cbc4b0c4b3af423356d431c
|
fed6e1017a0dbae0b50169a588a0e6e7b04222af
|
/typical90/solved/32.cpp
|
3d400fb6bb570571b5c34e0f439023b226351e72
|
[] |
no_license
|
yukimiii/competitive-programming
|
1d8a69ded2532b177b43f077c16a27f2d6fa27f1
|
cdec5d902ba2a87c8d7d1d3ed25182ca5693fe04
|
refs/heads/main
| 2023-07-19T04:57:40.789558
| 2021-09-16T07:15:57
| 2021-09-16T07:15:57
| 385,468,197
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 944
|
cpp
|
32.cpp
|
#include <bits/stdc++.h>
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(w, n) FOR(w, 0, n)
using namespace std;
typedef long long ll;
int main()
{
int n;
cin >> n;
vector<vector<ll>> vv(n, vector<ll>(n));
REP(i, n)
{
REP(j, n) { cin >> vv[i][j]; }
}
int m;
cin >> m;
int re[n][n] = {};
REP(i, m)
{
int a, b;
cin >> a >> b;
re[min(a, b) - 1][max(a, b) - 1]++;
}
ll ans = 1000000000000;
int len = n;
vector<int> vec(len);
for (int i = 0; i < len; i++)
vec[i] = i;
do
{
ll tmp = 0;
for (int i = 0; i < len; i++)
{
if (i != n - 1)
if (re[vec[i + 1]][vec[i]] || re[vec[i]][vec[i + 1]])
break;
// cout << vv[vec[i]][i] << endl;
tmp += vv[vec[i]][i];
if (i == n - 1)
{
// cout << tmp << endl;
ans = min(ans, tmp);
}
}
} while (next_permutation(vec.begin(), vec.end()));
if (ans == 1000000000000)
cout << -1 << endl;
else
cout << ans << endl;
return (0);
}
|
b2aed6d89c2ad5913575780594315e4516afe2d4
|
190398e9ea8f1159f643594043412b3620e7febb
|
/synthesizer/synthesizer.cpp
|
1081e782b1bb3e2bcc9a6f5a433a1ada709b8988
|
[] |
no_license
|
connormarshall/lofi-synth
|
d27c9c2552ba406e04e3499f175aaf2ea16622a8
|
ba5a5a94b271c20d4a2d36f234fab50b48c8baaa
|
refs/heads/master
| 2023-03-08T10:51:42.235778
| 2021-02-24T03:58:09
| 2021-02-24T03:58:09
| 340,941,842
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 8,390
|
cpp
|
synthesizer.cpp
|
// synthesizer.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include "olcNoiseMaker.h";
// Oscilator function types
#define OSC_SINE 0
#define OSC_SQUARE 1
#define OSC_TRIANGLE 2
#define OSC_SAW_ANA 3
#define OSC_SAW_DIG 4
#define OSC_SAW_REV 5
#define OSC_NOISE 6
// Holds output frequency
atomic<double> frequencyOutput = 0.0;
// Base octave: A3
double octaveBaseFrequency = 220.0;
// Scaling factor for 12-tone just intonation
const double twelfthRootOf2 = 1.0594630943592952645618252949463;
// Master Volume
double masterVolume = 0.4;
// Oscillator Used
int oscInUse = OSC_SINE;
// Takes a frequency (Hz) and returns it in angular velocity
double w(double hertz)
{
return hertz * 2 * PI;
}
// Takes a note in Hertz and what interval is wanted, returns the just intonation interval in Hertz.
// A positive interval returns a note in the higher octave, a negative in the lower.
double noteJustInterval(double note, int interval)
{
return note * pow(twelfthRootOf2, interval);
}
// Takes a note in Hertz and what interval is wanted, returns the equal temperament interval in Hertz.
// A positive interval returns a note in the higher octave, a negative in the lower.
double noteEqualInterval(int interval)
{
return octaveBaseFrequency * pow(twelfthRootOf2, interval);
}
string noteName(int interval)
{
// Array of note name assignments
const char* notes[] = { "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" };
int octave = interval / 12;
int idx = interval % 12;
string n = notes[idx];
return std::string(notes[idx]) + std::to_string(octave);
}
// Returns amplitude as a function of various types of oscilators
double osc(double hertz, double time, int type = OSC_SINE, double LFOHertz = 5.0, double LFOAmplitude = 0.002)
{
// Frequency (angular velocity * time) modulated by an LFO sine wave
double frequency = w(hertz) * time + LFOAmplitude * hertz * sin(w(LFOHertz) * time);
switch (type)
{
// Sine Wave
case OSC_SINE:
return sin(frequency);
// Square Wave
case OSC_SQUARE:
return sin(frequency) > 0.0 ? 1.0 : -1.0;
// Triangle Wave
case OSC_TRIANGLE:
return asin(sin(frequency)) * 2.0 / PI;
// Saw Wave (Analog)
case OSC_SAW_ANA:
{
double output = 0.0;
for (double n = 1.0; n < 100.0; n++) {
output += sin(n * frequency) / n;
}
return output * (2.0 / PI);
}
// Saw Wave (Digital)
case OSC_SAW_DIG:
{
// FREQUENCY MODULATION QUESTIONABLE FOR DIGITAL SAW WAVES
// Frequency is increasing with each period.
double normalizedHertz = hertz / (2.0 * PI);
double f = w(normalizedHertz) + LFOAmplitude * sin(w(LFOHertz) * time);
return (2.0 / PI) * (f * PI * fmod(time, 1.0 / f) - (PI / 2.0));
}
case OSC_SAW_REV:
{
// FREQUENCY MODULATION QUESTIONABLE FOR DIGITAL SAW WAVES
// Frequency is increasing with each period.
double normalizedHertz = hertz / (2.0 * PI);
double f = w(normalizedHertz) + LFOAmplitude * sin(w(LFOHertz) * time);
return (2.0 / PI) * atan(tan((PI / 2) - ((time * PI) / (1 / f))));
}
// Noise
case OSC_NOISE:
return 2.0 * ((double) rand() / (double) RAND_MAX) - 1.0;
// Arcatan-Cotan Saw Wave
default: 0.0;
}
}
// Envelope (Attack, Decay, Sustain, Release)
struct EnvelopeADSR
{
double attackTime;
double decayTime;
double releaseTime;
double attackAmplitude;
double sustainAmplitude;
// Time that the note starts playing
double triggerOnTime;
// Time that the note releases
double triggerOffTime;
bool noteOn;
EnvelopeADSR()
{
attackTime = 0.10;
decayTime = 0.01;
attackAmplitude = 1.0;
sustainAmplitude = 0.8;
releaseTime = 0.20;
triggerOffTime = 0.0;
triggerOnTime = 0.0;
noteOn = false;
}
wstring GetPhase(double time) {
wstring * phase = new wstring(L"ERR");
double lifeTime = time - triggerOnTime;
if (noteOn)
{
if (lifeTime <= attackTime)
phase = new wstring(L"ATTACK");
if (lifeTime > attackTime && lifeTime <= (decayTime + attackTime))
phase = new wstring(L"DECAY");
if (lifeTime > (attackTime + decayTime))
phase = new wstring(L"SUSTAIN");
}
else
phase = new wstring(L"RELEASE");
return *phase;
}
// Starts playing envelope
void NoteOn(double timeOn) {
triggerOnTime = timeOn;
noteOn = true;
}
// Releases envelope
void NoteOff(double timeOff) {
triggerOffTime = timeOff;
noteOn = false;
}
// Returns the amplitude of the envelope at a given time
double GetAmplitude(double time) {
// How long the note has been playing for
double lifeTime = time - triggerOnTime;
double amplitude = 0.0;
// y = mx + c : Amplitude = gradient * time (normalised to phase time) + base amplitude of phase
if (noteOn)
{
// Attack Phase (base amplitude is 0)
if (lifeTime <= attackTime)
{
amplitude =
attackAmplitude *
(lifeTime / attackTime);
}
// Decay Phase
if (lifeTime > attackTime && lifeTime <= (attackTime + decayTime))
{
amplitude =
(sustainAmplitude - attackAmplitude) *
((lifeTime - attackTime) / decayTime) +
attackAmplitude;
}
// Sustain Phase (constant amp)
if (lifeTime > (attackTime + decayTime))
amplitude = sustainAmplitude;
}
else
{
// Release Phase
amplitude =
(0.0 - sustainAmplitude) *
((time - triggerOffTime) / releaseTime) +
sustainAmplitude;
}
// Epsilon Check: Prevents tiny or negative amplitude
if (amplitude < 0.0001)
amplitude = 0.0;
return amplitude;
}
};
EnvelopeADSR envelope;
// Make a sound for some given time
double MakeNoise(double time)
{
double output = envelope.GetAmplitude(time) * osc(frequencyOutput, time, oscInUse);
// Master volume scaling
return output * masterVolume;
}
int main()
{
std::wcout << "lofi-synth" << std::endl;
// Get sound hardware
vector<wstring> devices = olcNoiseMaker<short>::Enumerate();
// Display what was found
for (auto d : devices) std::wcout << "Found sound device: " << d << std::endl;
// Create sound machine
olcNoiseMaker<short> sound(devices[0], 44100, 1, 8, 512);
sound.SetUserFunction(MakeNoise);
// Keyboard indicator
// Display a keyboard
wcout << endl <<
" ._________________________________________________________." << endl <<
" | | | | | | | | | | | | | | | | |" << endl <<
" | | S | | | F | | G | | | J | | K | | L | | |" << endl <<
" | |___| | |___| |___| | |___| |___| |___| | |__" << endl <<
" | | | | | | | | | | |" << endl <<
" | Z | X | C | V | B | N | M | , | . | / |" << endl <<
" |_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|" << endl << endl;
// Tracks which key was pressed
int currentKey = -1;
bool keyDown = false;
while (1)
{
// Keyboard
keyDown = false;
for (int k = 0; k < 17; k++)
{
if (GetAsyncKeyState((unsigned char)("ZSXCFVGBNJMK\xbcL\xbe\xbf"[k])) & 0x8000)
{
if (currentKey != k)
{
envelope.NoteOn(sound.GetTime());
frequencyOutput = noteEqualInterval(k);
currentKey = k;
// Array of note name assignments
const char* notes[] = { "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" };
int octave = (k + 24) / 12;
int idx = k % 12;
string n = notes[idx];
wcout << "\r Note: " << notes[idx] << octave <<
" Pitch: " << frequencyOutput << " ";
}
keyDown = true;
}
if (GetAsyncKeyState((unsigned char)("1234567"[k])) & 0x8000)
{
oscInUse = k;
}
}
if (!keyDown)
{
if (currentKey != -1)
{
envelope.NoteOff(sound.GetTime());
currentKey = -1;
}
}
if(oscInUse == 0)
wcout << L"\r Osc: SINE";
if (oscInUse == 1)
wcout << L"\r Osc: SQUARE";
if (oscInUse == 2)
wcout << L"\r Osc: TRIANGLE";
if (oscInUse == 3)
wcout << L"\r Osc: ANALOG SAW";
if (oscInUse == 4)
wcout << L"\r Osc: DIGITAL SAW";
if (oscInUse == 5)
wcout << L"\r Osc: REVERSE SAW";
if (oscInUse == 6)
wcout << L"\r Osc: NOISE";
wcout << " Env: " << envelope.GetPhase(sound.GetTime()) << " ";
}
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
|
1fef48a36a667123878b1f2bd8b3300ed4856053
|
3da7190f48b8f8c6b731e574d3fea48b20b91b8c
|
/MNIST/nn_controller.cpp
|
36ed6fe96811f419131cf20c8434fe1dab885e89
|
[] |
no_license
|
aaddaamm30/tohoku_nn_research
|
157ae535ca8a113ed6c9a7dbe852398e1e1f46c2
|
6df6b7560f42f310aad2a96363b19215cceae61a
|
refs/heads/master
| 2021-01-20T01:46:02.809323
| 2019-01-09T23:38:07
| 2019-01-09T23:38:07
| 89,326,672
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 14,307
|
cpp
|
nn_controller.cpp
|
/****************************************************************
*
* File : nn_controller.cpp
* Description : structual support for the neural_controller
* class. Handles reading and writing weights
* through the backbone to the weight driver
* and vice versa. Also uses reader_mnist class
* to pipe in values to the backbone.
*
*
* Author : Adam Loo
* Last Edited : Wed Jul 12 2017
*
****************************************************************/
#include <iostream>
#include <Eigen/Dense>
#include <fstream>
#include <iomanip>
#include "read_mnist.h"
#include "weight_driver.h"
#include "nn_engine.h"
#include "nn_controller.h"
/////////////////////////////////////////////////////////////
//setters
// - setters for epoc and batch size
/////////////////////////////////////////////////////////////
int neural_controller::setEpoch(int i){
m_numEpoch = i;
return(0);
}
int neural_controller::setBatch(int i){
m_batchSize = i;
return(0);
}
/////////////////////////////////////////////////////////////
//funciton that checks path
// - checks if path has a valid name and saves it to
// the class
/////////////////////////////////////////////////////////////
int neural_controller::establishPath(std::string fh){
file_io m;
if(m.validateFileName(fh))
return(1);
m_fh = fh;
return(0);
}
/////////////////////////////////////////////////////////////
//train function
// - when called this funciton runs through the train
// mnist data epoch number of times with a batch size
// of batch. uses m_updateGradients array of matrixes as
// a running sum then divides the them by batch at the end
// of a batch and applies that update to each weight
// - writes weights to m_fh at the end.
/////////////////////////////////////////////////////////////
int neural_controller::train(void){
//mnist index counter
int mnIdx = 0;
//weight matrices
Eigen::MatrixXf* w1;
Eigen::MatrixXf* w2;
Eigen::MatrixXf* w3;
// Eigen::MatrixXf* w4;
Eigen::MatrixXf** endWeights = new Eigen::MatrixXf*[3];
//matrix of image vectors and vector of lables
Eigen::MatrixXf* tmpMx = m_training_block->getImgI();
Eigen::VectorXi* lblVecs = m_training_block->getLblI();
Eigen::MatrixXi imgVecs(tmpMx->rows(),tmpMx->cols());
Eigen::VectorXi oneImg(784);
imgVecs = tmpMx->cast<int>();
//manip varbs
int num_imgs=tmpMx->cols();
int batchIdx=0;
//file reader object
file_io f;
//generate weights
if(f.file_exists(m_fh)){
std::cout<<"WEIGHTS: reading in from file ["<<m_fh<<"]\n";
if(f.readWeights(&w1,&w2,&w3,/*&w4,*/m_fh)){
std::cout<<"ERROR: failure to read weights from file ["<<m_fh<<"]\n";
return(1);
}
}else{
std::cout<<"WEIGHTS: initializing to random\n";
if(f.randomizeWeights(&w1, &w2, &w3/*, &w4*/)){
std::cout<<"ERROR: failure to randomize weights\n";
return(1);
}
}
std::cout<<"WEIGHTS: writing into network\n";
//write weights
if(p_setMatrixWeights(w1, w2, w3/*, w4*/)){
std::cout<<"ERROR: failure to set weights in network\n";
return(1);
}
//test for epoch number of times
for(int a=0; a<m_numEpoch; a++){
std::cout<<"BEGINING EPOCH #"<<a+1<<std::endl;
//reset index to beginning of training set
mnIdx = 0;
//run test batch number of times while there are still at least
//batch number input vectors left
while((num_imgs - mnIdx) >= m_batchSize){
for(int m=0; m<m_batchSize; m++){
//enter img vector
for(int l=0; l<784; l++){
oneImg(l) = imgVecs(l, mnIdx);
}
if(p_setInputVector(&oneImg)){
std::cout<<"ERROR: fail to set image input vector in network\n";
return(1);
}
std::cout<<"NETWORK [input] : forward pass img ["<<mnIdx+1<<"] with label <"<<(*lblVecs)(mnIdx)<<">\n";
//pass through network
std::cout<<"NETWORK [output]: evaluated to ["<<p_runNetwork()<<"]\n";
p_runNetwork();
//backpropogate with label value
if(p_backprop((*lblVecs)(mnIdx),m_batchSize)){
std::cout<<"ERROR: failure at backpropogation step\n";
return(1);
}
//increment index pointer
mnIdx++;
}
batchIdx++;
std::cout<<"NETWORK: batch ["<<batchIdx<<"] complete || updating weights\n";
//average gradients and apply to weights
if(p_updateWeights()){
std::cout<<"ERROR: weight update unsuccessfull\n";
return(1);
}
}
//complete remainder
int numLeft = num_imgs - mnIdx;
if(numLeft > 0){
std::cout<<"NETWORK: Less then ["<<m_batchSize<<"] images left running batch of size ["<<numLeft<<"]\n";
for(int i=0; i < numLeft; i++){
for(int l=0; l<784; l++){
oneImg(l) = imgVecs(l, mnIdx);
}
if(p_setInputVector(&oneImg)){
std::cout<<"ERROR: fail to set image input vector in network\n";
return(1);
}
//pass through network
p_l1Pass();
p_l2Pass();
p_l3Pass();
// p_l4Pass();
p_softmax();
//backpropogate with label value
if(p_backprop((*lblVecs)(mnIdx), numLeft)){
std::cout<<"ERROR: failure at backpropogation step\n";
return(1);
}
//increment index pointer
mnIdx++;
}
}
//apply update to network weights
if(p_updateWeights()){
std::cout<<"ERROR: weight update unsuccessfull\n";
return(1);
}
}
//write matrices to m_fh using the f file reader
endWeights = p_getWeights();
// dbg<<"endwrite\n"<<*endWeights[0]<<std::endl;
if(f.writeWeights(endWeights[0],endWeights[1],endWeights[2],/*endWeights[3],*/m_fh)){
std::cout<<"ERROR: failure to write weights to ["<<m_fh<<"]\n";
return(1);
}
std::cout<<"SUCCESS: Trained weights written to ["<<m_fh<<"]\n";
std::cout<<" epochs = "<<m_numEpoch<<"\n";
std::cout<<" batch size = "<<m_batchSize<<"\n";
return(0);
}
/////////////////////////////////////////////////////////////
//test function
// - when called this funciton runs throught the testing
// set of the MNIST data and evaluates accuracy of network
// weights.
// - validates inputted fh as well
/////////////////////////////////////////////////////////////
int neural_controller::test(void){
//file io object
file_io f;
//load up weights
Eigen::MatrixXf* w1;
Eigen::MatrixXf* w2;
Eigen::MatrixXf* w3;
// Eigen::MatrixXf* w4;
//get data from mnist
Eigen::MatrixXf* tmpMx = m_testing_block->getImgI();
Eigen::VectorXi* lblVecs = m_testing_block->getLblI();
Eigen::MatrixXi imgVecs(tmpMx->rows(),tmpMx->cols());
Eigen::VectorXi inImg(tmpMx->rows());
imgVecs = (*tmpMx).cast<int>();
//score chart
int num_imgs = tmpMx->cols();
int size_img = tmpMx->rows();
int num_correct = 0;
int net_guess;
std::cout<<"\n======================";
std::cout<<"\n=====RUNNING TEST=====\n";
//generate weights
if(f.file_exists(m_fh)){
std::cout<<"WEIGHTS: reading in from file ["<<m_fh<<"]\n";
if(f.readWeights(&w1,&w2,&w3,/*&w4,*/ m_fh)){
std::cout<<"ERROR: failure to read weights from file ["<<m_fh<<"]\n";
return(1);
}
}else{
std::cout<<"WEIGHTS: reading in from file ["<<m_fh<<"]\n";
std::cout<<"FILE-NOT-FOUND\n\nWEIGHTS: initializing to random\n\n";
if(f.randomizeWeights(&w1, &w2, &w3/*, &w4*/)){
std::cout<<"ERROR: failure to randomize weights\n";
return(1);
}
}
//write weights
if(p_setMatrixWeights(w1, w2, w3/*, w4*/)){
std::cout<<"ERROR: failure to set weights in network\n";
return(1);
}
//loop though all test imgs and labels and output accuracy
for(int i=0;i<num_imgs;i++){
for(int l=0; l<size_img; l++){
inImg(l) = imgVecs(l,i);
}
if(p_setInputVector(&inImg)){
std::cout<<"ERROR: fail to set image input vector in network\n";
return(1);
}
//get network guess
net_guess = p_runNetwork();
//itterate if correct
if(net_guess == (*lblVecs)(i)){
std::cout<<"Test img ["<<i<<"] CORRECT (value: "<<(*lblVecs)(i)<<")"<<std::endl;
num_correct++;
}else{
std::cout<<"Test img ["<<i<<"] incorrect (value: "<<(*lblVecs)(i)<<" || NN guess: "<<net_guess<<")"<<std::endl;
}
}
std::cout<<"TEST COMPLETE\n";
std::cout<<"Number of trials = "<<num_imgs<<std::endl;
std::cout<<"Number correct = "<<num_correct<<std::endl;
std::cout<<"Accuracy = "<<((float)num_correct / num_imgs)*100<<"%\n";
return(0);
}
/////////////////////////////////////////////////////////////
//Full send
// - same as train but runs a test set between each epoch
/////////////////////////////////////////////////////////////
int neural_controller::fullSend(void){
//get user input
int epoch, batch, mnIdx, net_guess, num_correct=0;
float step;
std::cout<<"\nFULL SEND BRUH\n";
std::cout<<"Epoch : ";
std::cin>>epoch;
std::cout<<"\nBatch : ";
std::cin>>batch;
std::cout<<"\nstep : ";
std::cin>>step;
if(epoch<=0||batch<=0||step <=0){
std::cout<<"\n\n||INVALID INPUT||\n";
return(1);
}
file_io f;
m_numEpoch = 1;
m_batchSize = batch;
p_setStepSize(step);
//load up info (will be a lot :O)
//testing below
Eigen::MatrixXf* tmpMx = m_testing_block->getImgI();
Eigen::VectorXi* TEST_lbl = m_testing_block->getLblI();
Eigen::MatrixXi TEST_img(tmpMx->rows(),tmpMx->cols());
TEST_img = tmpMx->cast<int>();
//training below
tmpMx = m_training_block->getImgI();
Eigen::VectorXi* TRAIN_lbl = m_training_block->getLblI();
Eigen::MatrixXi TRAIN_img(tmpMx->rows(),tmpMx->cols());
TRAIN_img = tmpMx->cast<int>();
//init vector for one img
Eigen::VectorXi INIT_img(tmpMx->rows());
//randomize that $H!T
Eigen::MatrixXf* w1;
Eigen::MatrixXf* w2;
Eigen::MatrixXf* w3;
if(f.randomizeWeights(&w1, &w2, &w3/*, &w4*/)){
std::cout<<"ERROR: failure to randomize weights\n";
return(1);
}
std::cout<<"WEIGHTS: writing into network\n";
//write weights
if(p_setMatrixWeights(w1, w2, w3/*, w4*/)){
std::cout<<"ERROR: failure to set weights in network\n";
return(1);
}
//top level loop to run through all processes
for(int loopnum = 0; loopnum < epoch; loopnum++){
std::cout<<"\nEPOCH TRAIN #"<<loopnum+1<<std::endl;
//reset index to beginning of training set
mnIdx = 0;
//run test batch number of times while there are still at least
//batch number input vectors left
while((TRAIN_img.cols() - mnIdx) >= m_batchSize){
for(int m=0; m<m_batchSize; m++){
//enter img vector
for(int l=0; l<784; l++){
INIT_img(l) = TRAIN_img(l, mnIdx);
}
if(p_setInputVector(&INIT_img)){
std::cout<<"ERROR: fail to set image input vector in network\n";
return(1);
}
p_runNetwork();
//backpropogate with label value
if(p_backprop((*TRAIN_lbl)(mnIdx),m_batchSize)){
std::cout<<"ERROR: failure at backpropogation step\n";
return(1);
}
//increment index pointer
mnIdx++;
}
//average gradients and apply to weights
if(p_updateWeights()){
std::cout<<"ERROR: weight update unsuccessfull\n";
return(1);
}
}
std::cout<<"COMPLETE -> TESTING\n";
//one test output a accuracy to console
mnIdx = 0;
num_correct = 0;
//loop though all test imgs and labels and output accuracy
for(int i=0;i<TEST_img.cols();i++){
for(int l=0; l<TEST_img.rows(); l++){
INIT_img(l) = TEST_img(l,i);
}
if(p_setInputVector(&INIT_img)){
std::cout<<"ERROR: fail to set image input vector in network\n";
return(1);
}
//get network guess
net_guess = p_runNetwork();
//itterate if correct
if(net_guess == (*TEST_lbl)(i)){
num_correct++;
}
}
std::cout<<"TEST COMPLETE\n";
std::cout<<"Number correct = "<<num_correct<<std::endl;
std::cout<<"Accuracy = "<<((float)num_correct / TEST_img.cols())*100<<"%\n";
}
return(0);
}
/////////////////////////////////////////////////////////////
//unit test to see intermediate values in a single forward
//pass operation
/////////////////////////////////////////////////////////////
int neural_controller::unit_fpv(std::string wdat){
//get data
Eigen::MatrixXf* s = m_training_block->getImgI();
Eigen::VectorXi* v = m_training_block->getLblI();
Eigen::VectorXi in(784);
Eigen::VectorXf** vec = new Eigen::VectorXf*[6];
//weights
Eigen::MatrixXf* w1;
Eigen::MatrixXf* w2;
Eigen::MatrixXf* w3;
// Eigen::MatrixXf* w4;
//select random object
int idx = std::rand() % 60000;
int result;
//file io object
file_io f;
//file control
std::ofstream unitfile;
//file name
std::string fh = "unit_forward_pass_test.txt";
std::cout<<"========================\n";
std::cout<<"=FORWARD PASS UNIT TEST=\n";
std::cout<<"UNIT: evaluating file name\n";
if(f.validateFileName(wdat)){
std::cout<<"FILE: file name not valid, randomizing weights\n";
f.randomizeWeights(&w1, &w2, &w3/*, &w4*/);
}else if(f.file_exists(wdat) && (!f.validateFileName(wdat))){
std::cout<<"FILE: reading weights from ["<<wdat<<"]\n";
f.readWeights(&w1, &w2, &w3, /*&w4,*/ wdat);
}else{
std::cout<<"FILE: ["<<wdat<<"] not found. randomizing weigths\n";
f.randomizeWeights(&w1, &w2, &w3/*, &w4*/);
}
std::cout<<"UNIT: loading up weights into network\n";
p_setMatrixWeights(w1, w2, w3/*, w4*/);
std::cout<<"UNIT: loading up image into network\n";
//load up image
for(int l=0; l<784; l++){
in(l) = (*s)(l,idx);
}
if(p_setInputVector(&in)){
std::cout<<"ERROR: fail to set image input vector in network\n";
return(1);
}
//pass image through network
result = p_runNetwork();
std::cout<<"NETWORK: label ["<<(*v)(idx)<<"] network evaluation ["<<result<<"]\n";
//getting fpv and writing into file
unitfile.open(fh);
vec = p_getFPV();
unitfile<<"FORWARD PASS VECTOR UNIT TEST\n";
unitfile<<"\n m_v1_w|m_v1_a\n";
for(int i=0;i<vec[0]->rows();i++){
unitfile<<std::setw(10)<<(*vec[0])(i)<<"|"<<(*vec[1])(i)<<std::endl;
}
unitfile<<"\n m_v2_w|m_v2_a\n";
for(int i=0;i<vec[2]->rows();i++){
unitfile<<std::setw(10)<<(*vec[2])(i)<<"|"<<(*vec[3])(i)<<std::endl;
}
unitfile<<"\n m_v3_w\n";
for(int i=0;i<vec[4]->rows();i++){
unitfile<<std::setw(10)<<(*vec[4])(i)<<std::endl;
}
/* unitfile<<"\n m_v4_w|m_v4_a\n";
for(int i=0;i<vec[6]->rows();i++){
unitfile<<std::setw(10)<<(*vec[6])(i)<<"|"<<(*vec[7])(i)<<std::endl;
}
*/
unitfile<<"\noutvec\n";
for(int i=0;i<vec[5]->rows();i++)
unitfile<<(*vec[5])(i)<<", ";
unitfile.close();
std::cout<<"UNIT: vector values written to ["<<fh<<"]\n";
return(0);
}
|
b600100b4692f1eaf1573b9175ccac9f358a09b3
|
67c59778d6e05181c1ab92717927259aa3544a7f
|
/Source/VCLUtils/AnsiStringUtils_.h
|
82479808cd49fc01f8224b01e517a1683246461e
|
[] |
no_license
|
fpawel/stg3old
|
2640358c2b278cc08e7367d3e11dff4f2651b0a7
|
df01e48047bef6c75d6bc34aeadf17c2958d681f
|
refs/heads/master
| 2020-03-28T23:00:27.287834
| 2019-03-13T08:20:43
| 2019-03-13T08:20:43
| 149,270,631
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,746
|
h
|
AnsiStringUtils_.h
|
//---------------------------------------------------------------------------
#ifndef AnsiStringUtils_H
#define AnsiStringUtils_H
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <utility>
#define MYSPRINTF_ AnsiString().sprintf
// translates a specified number of characters in a string into the OEM-defined character set
AnsiString MyStringToOem( const AnsiString& );
AnsiString BoolArrayToStr( const bool* b, const bool* e );
void StrToBoolArray( bool* b, bool* e, const AnsiString& s );
typedef std::pair<double,bool> MyDouble;
MyDouble MyStrToD( const AnsiString& s );
bool MyTryStrToFloat( const AnsiString& s, double* pVal = NULL );
typedef std::pair<long,bool> MyInt;
MyInt MyStrToInt( const AnsiString& s, int radix = 10 );
AnsiString MyFormatFloat( double v, int n );
AnsiString MyDToStr( const MyDouble& v, int n );
void ShowUserInputError(const AnsiString& fld, const AnsiString& val);
AnsiString MyBuffToStr( const unsigned char *buffer, const unsigned char *bufferEnd,
const AnsiString& ss = "" );
AnsiString MakeFileNameAsDate( const AnsiString& dir, const AnsiString& ext,
TDateTime date, const AnsiString& add_back = "" );
AnsiString DateToPath( TDateTime date );
AnsiString DateToFilename( TDateTime date );
bool IsAlphaNumber( const AnsiString& s );
AnsiString NormString( const AnsiString& s )
{
return s.IsEmpty() ? AnsiString(" ") : s;
}
unsigned CountAfterCommaDigits(double v);
AnsiString MyDateTimeToStr(TDateTime);
AnsiString MyFormatMonth( unsigned month );
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
|
55f5aeb2b25a7ba1f0adf37de4409ad11b2e27fc
|
6ed5ffddef4fc4033742b88e3ebf14e8660cf4c1
|
/AI/AIRacer.h
|
6f9a1f42ce167e8c784b52f588de2e33f3d9afb6
|
[] |
no_license
|
erenik/SpaceRace
|
5e4b169b7aefa264305b33f5f52c9883f63cd787
|
d9f441ab3a7f80f394be1e9f90f0fe379fcf0040
|
refs/heads/master
| 2021-01-17T16:45:05.592070
| 2016-06-20T22:49:30
| 2016-06-20T22:49:30
| 57,668,489
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,077
|
h
|
AIRacer.h
|
// Emil Hedemalm
// 2013-07-28
#ifndef AI_RACER_H
#define AI_RACER_H
#include "AI/AI.h"
#include "MathLib.h"
class RacingShipGlobal;
class Racing;
class Entity;
class SRPlayer;
class Waypoint;
class Path;
class AIRacer : public AI {
public:
AIRacer(Entity * shipEntity, SRPlayer * player, RacingShipGlobal * shipState, Racing * gameState);
virtual ~AIRacer();
virtual void Process(float timeInSeconds);
/// Reset so it gathers variables again.
void Reset();
// WOshi.
virtual void ProcessMessage(Message * message);
/// For disabling/enabling only certain aspects of the AI.
bool autoThrust;
bool autoTurn;
private:
/// For smoother turns.
void CalculateNextAverage();
/// To the next checkpoint. If this is exceeded by x2 at any time it means we missed the checkpoint, so reset.
float closestDistance;
Entity * shipEntity;
SRPlayer * player;
RacingShipGlobal * shipState;
Racing * gameState;
const Waypoint * closestWaypoint;
List<const Waypoint *> nextWaypoints;
Vector3f nextWaypointAverage;
int nextCheckpointIndexuu;
Path * path;
};
#endif
|
1ad0928dc4cf7f1c70a6362ab84c5df0bc99143e
|
f10a7a5e92f2d657ec7f5be87cd862792cad4772
|
/server/proba2/widget.cpp
|
9e3acbce8af5c9ac6d1e23ec2e013d3a07a5bcf7
|
[] |
no_license
|
shiroyasha/oldPorjects
|
88af98532bb9232c2a036346a0f2d3d77b7ca2fe
|
b062bcaceb2a1919e23a04877e06037e50f862c0
|
refs/heads/master
| 2021-01-10T21:17:10.678714
| 2012-12-05T13:44:13
| 2012-12-05T13:44:13
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 384
|
cpp
|
widget.cpp
|
#include "widget.h"
#include <QPainter>
#include <QDebug>
widget::widget(QWidget *parent) :
QWidget(parent)
{
m_x = 1;
m_y = 1;
}
void widget::paintEvent(QPaintEvent *e)
{
QPainter p;
p.begin(this);
p.drawRect( m_x, m_y, 100, 100);
p.end();
qDebug() << m_x << m_y;
}
void widget::crtaj( int x, int y)
{
m_x = x;
m_y = y;
update();
}
|
c5c733d0a06b63ecb4885de2bacb4e922ac29faf
|
6d2e9d2dc37fb9f2a8cb77eeb926741185e481e7
|
/apps/maxtree_comparison/bench_serial_hqueue.cpp
|
933a654d482ac7782e27a44d49ab8ea4c7ee9b57
|
[] |
no_license
|
onvungocminh/The-Dahu-distance
|
ad41a1412b85bcb00f449a74188f923fa2fd59e3
|
edbb135c5a5195c9bf591bf409c796c0f45517b7
|
refs/heads/master
| 2022-06-17T18:27:39.804634
| 2020-05-05T19:14:57
| 2020-05-05T19:14:57
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 124
|
cpp
|
bench_serial_hqueue.cpp
|
#include "bench_maxtree_algorithm.hpp"
int main(int argc, char** argv)
{
run_test(argc, argv, meta_serial_hqueue ());
}
|
4dc50227849ff7a3ac4c87af0369e323949cfd68
|
ec68c973b7cd3821dd70ed6787497a0f808e18e1
|
/Cpp/SDK/Dialog_OkDialogAlt_parameters.h
|
60c9de652797aa0def7f3cb7e2897e93f12c0ed9
|
[] |
no_license
|
Hengle/zRemnant-SDK
|
05be5801567a8cf67e8b03c50010f590d4e2599d
|
be2d99fb54f44a09ca52abc5f898e665964a24cb
|
refs/heads/main
| 2023-07-16T04:44:43.113226
| 2021-08-27T14:26:40
| 2021-08-27T14:26:40
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 793
|
h
|
Dialog_OkDialogAlt_parameters.h
|
#pragma once
// Name: Remnant, Version: 1.0
/*!!DEFINE!!*/
/*!!HELPER_DEF!!*/
/*!!HELPER_INC!!*/
#ifdef _MSC_VER
#pragma pack(push, 0x01)
#endif
namespace CG
{
//---------------------------------------------------------------------------
// Parameters
//---------------------------------------------------------------------------
// Function Dialog_OkDialogAlt.Dialog_OkDialogAlt_C.OnBeginDialog
struct ADialog_OkDialogAlt_C_OnBeginDialog_Params
{
};
// Function Dialog_OkDialogAlt.Dialog_OkDialogAlt_C.OnEndDialog
struct ADialog_OkDialogAlt_C_OnEndDialog_Params
{
};
// Function Dialog_OkDialogAlt.Dialog_OkDialogAlt_C.ExecuteUbergraph_Dialog_OkDialogAlt
struct ADialog_OkDialogAlt_C_ExecuteUbergraph_Dialog_OkDialogAlt_Params
{
};
}
#ifdef _MSC_VER
#pragma pack(pop)
#endif
|
eb916b19ecacc5beeb098ba88dd20a7156dcc1bc
|
c09debdf9721a95e44417d4d01ec6dcd643569b5
|
/cpp_algorithms/Problems_461_HammingDistance.cpp
|
9a3ad91df56c81e5ebc4196cd0250df50d6c1c9c
|
[] |
no_license
|
minwookim/algorithm_problems
|
f2c438c647ec8206d56d6b8490fce8cc3e253126
|
1cfbe5d217757882ac9239fa127b41b13e8e50f3
|
refs/heads/main
| 2023-04-10T13:48:07.517853
| 2021-04-20T04:44:24
| 2021-04-20T04:44:24
| 360,805,640
| 0
| 0
| null | 2021-04-23T07:50:36
| 2021-04-23T07:50:35
| null |
UTF-8
|
C++
| false
| false
| 371
|
cpp
|
Problems_461_HammingDistance.cpp
|
#include <iostream>
#include <bitset>
using namespace std;
class Solution {
public:
int hammingDistance(int x, int y) {
bitset<32> xBit(x);
bitset<32> yBit(y);
int count = 0;
for (int i = 0; i < xBit.size(); ++i)
if (xBit[i] == yBit[i])
++count;
return 32 - count;
}
};
//int main(int argc, char *argv[]) {
//
// cout << "Hell o" << endl;
//
//}
|
364e1f570fee51ac0811df2999d924022b3c1949
|
ca32d531ff2596425ce5218a8e2b732a6744faa0
|
/asterisk-cpp/src/manager/actions/SetCdrUserFieldAction.cpp
|
e391fff2a213dcf32901f70a458c55b5a0bc87b1
|
[
"Apache-2.0"
] |
permissive
|
augcampos/asterisk-cpp
|
a8a115a164194db6e9712c676111af164a8526fb
|
921423e0d1b6042d0ce2be6d7b9d98af4feb7460
|
refs/heads/master
| 2022-07-06T00:37:41.907214
| 2022-07-01T03:51:25
| 2022-07-01T03:51:25
| 2,310,863
| 22
| 15
| null | 2017-09-26T00:10:45
| 2011-09-01T23:05:30
|
C++
|
UTF-8
|
C++
| false
| false
| 1,483
|
cpp
|
SetCdrUserFieldAction.cpp
|
/*
* SetCdrUserFieldAction.h
*
* Created on: Jun 27, 2013
* Author: augcampos
*/
#include "asteriskcpp/manager/actions/SetCdrUserFieldAction.h"
namespace asteriskcpp {
SetCdrUserFieldAction::SetCdrUserFieldAction() {
}
SetCdrUserFieldAction::~SetCdrUserFieldAction() {
}
SetCdrUserFieldAction::SetCdrUserFieldAction(const std::string& channel, const std::string& userField) {
this->setChannel(channel);
this->setUserField(userField);
}
SetCdrUserFieldAction::SetCdrUserFieldAction(const std::string& channel, const std::string& userField, bool append) {
this->setChannel(channel);
this->setUserField(userField);
this->setAppend(append);
}
const std::string& SetCdrUserFieldAction::getChannel() const {
return (getGetterValue(__FUNCTION__));
}
void SetCdrUserFieldAction::setChannel(const std::string& channel) {
setSetterValue(__FUNCTION__, channel);
}
const std::string& SetCdrUserFieldAction::getUserField() const {
return (getGetterValue(__FUNCTION__));
}
void SetCdrUserFieldAction::setUserField(const std::string& userField) {
setSetterValue(__FUNCTION__, userField);
}
bool SetCdrUserFieldAction::getAppend() const {
return (getGetterValue<bool>(__FUNCTION__));
}
void SetCdrUserFieldAction::setAppend(bool append) {
setSetterValue<bool>(__FUNCTION__, append);
}
} //NAMESPACE
|
2eb9a43a18f1397a5bc6cdb3dc627ea266bb9325
|
e2eeb3d362c55e678c559e3a85500b26b0a38e77
|
/src/Thread.h
|
03eecbfc8ce6b632279377151546da8ffb3e3357
|
[] |
no_license
|
LJH960101/JHNet
|
b016f2dc76f291b7b5d929ff71e218a17c7e53cd
|
99159c849576457935fb0234a4d5eed8ea78657d
|
refs/heads/master
| 2023-05-07T08:28:10.898085
| 2021-05-31T08:33:21
| 2021-05-31T08:33:21
| 325,768,993
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 289
|
h
|
Thread.h
|
#pragma once
#include <thread>
class CThread{
public:
CThread();
~CThread();
bool Begin();
void End();
protected:
virtual void _Tick() = 0;
private:
void _ThreadProc();
std::thread m_thread;
volatile bool m_bRunning;
volatile bool m_bTerminated;
};
|
4459503545fc9334aebaba971851e40e1480b09c
|
6ab9a3229719f457e4883f8b9c5f1d4c7b349362
|
/uva/Volume I/00167.cpp
|
eb28508f29fcf5996205b595a02b572a624b1ba1
|
[] |
no_license
|
ajmarin/coding
|
77c91ee760b3af34db7c45c64f90b23f6f5def16
|
8af901372ade9d3d913f69b1532df36fc9461603
|
refs/heads/master
| 2022-01-26T09:54:38.068385
| 2022-01-09T11:26:30
| 2022-01-09T11:26:30
| 2,166,262
| 33
| 15
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 902
|
cpp
|
00167.cpp
|
/////////////////////////////////
// 00167 - The Sultan's Successors
/////////////////////////////////
#include<cstdio>
#include<cstdlib>
#define MAXCAND 8
unsigned int cnum,i,j,max,temp;
char m[8][8];
void getcand(int a[], int k, int c[], int *cnd){
int i,j;
bool go;
*cnd = 0;
for(i = 0; i < 8; i++){
go = 1;
for(j = 0; go && j < k ; j++)
go = !(abs(k-j) == abs(i-a[j]) || a[j] == i);
if(go) c[(*cnd)++] = i;
}
}
void btrack(int a[], int k){
int c[8];
int cand = 8;
int i;
if(k == 8){
for(temp = i = 0; i < 8; i++) temp += m[i][a[i+1]];
if(temp > max) max = temp;
}
else {
++k;
getcand(a,k,c,&cand);
for (i = 0; i < cand; i++) {
a[k] = c[i];
btrack(a,k);
}
}
}
int main (void){
int a[9];
scanf("%d",&cnum);
while(cnum--){
max = 0;
for(i = 0; i < 8; i++) for(j = 0; j < 8; j++) scanf("%u",&m[i][j]);
btrack(a,0);
printf("%5u\n",max);
}
return 0;
}
|
ce6a2b26ce95ee94c2e8135399549e4325f8e950
|
04809ec45c1de2047da142e9e91f2cc71f4ee6eb
|
/VulkanTest1/GameObjectManager.h
|
8d5d404cd657cf39dfa2df3d8308f0ecb1fdd76e
|
[] |
no_license
|
PazerOP/VulkanTest1
|
3296e77280c4b2645eb97d9c6b8ec08b444d3377
|
ae29ce2fca771d01685a8454b7a060976e7171af
|
refs/heads/master
| 2021-01-20T14:22:39.914441
| 2017-05-27T21:19:59
| 2017-05-27T21:19:59
| 90,596,667
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 219
|
h
|
GameObjectManager.h
|
#pragma once
class IGameObject;
class GameObjectManagerImpl
{
public:
GameObjectManagerImpl();
private:
std::vector<std::shared_ptr<IGameObject>> m_GameObjects;
};
extern GameObjectManagerImpl& GameObjectManager();
|
b633a0adb975774ca00ad06c5823aa72adb755f9
|
5eec5d7633f043db35ab078589811ce8391a4855
|
/Projects/SolverTest/Macroblock_Utilities/Common/KernelCommon.h
|
c37165bdc82d4976936d14a0b342cec1b09c3a5a
|
[] |
no_license
|
uwgraphics/HierarchicalSolver
|
842f627feba18f2bebcd35217e5452fef168cc27
|
23fba2571307dc475d13d32cb248048e14a62264
|
refs/heads/master
| 2020-05-23T06:58:53.681850
| 2019-05-14T17:08:04
| 2019-05-14T17:08:04
| 186,670,294
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 11,977
|
h
|
KernelCommon.h
|
//#####################################################################
// Copyright (c) 2011-2013 Nathan Mitchell, Eftychios Sifakis.
// This file is covered by the FreeBSD license. Please refer to the
// license.txt file for more information.
//#####################################################################
#ifndef __KERNEL_COMMON_H__
#define __KERNEL_COMMON_H__
#include <type_traits>
//
// Don't define here. Use FIB=1 on the makefile command line.
//
//#define FORCE_IDENTICAL_BEHAVIOR
//
// Don't define here.
//
//#define ENABLE_DOUBLE_SUPPORT
//
// Enable use of c++ std io to print Number's
//
//#define ENABLE_IO_SUPPORT
//
// Enable INTEL VECTOR ARCHETECTURES
//
//#define ENABLE_SSE_INSTRUCTION_SET
//#define ENABLE_AVX_INSTRUCTION_SET
//#define ENABLE_MIC_INSTRUCTION_SET
//
// Enable ARM VECTOR ARCHETECTURES
//
//#define ENABLE_NEON_INSTRUCTION_SET
#if defined(ENABLE_SSE_INSTRUCTION_SET)
#include <immintrin.h>
#ifndef __INTEL_COMPILER
#include <pmmintrin.h>
#endif
#endif
#if defined(ENABLE_AVX_INSTRUCTION_SET)
#include <immintrin.h>
#ifndef __INTEL_COMPILER
#include <pmmintrin.h>
#endif
#endif
#if defined(ENABLE_AVX512_INSTRUCTION_SET)
#include <immintrin.h>
#ifndef __INTEL_COMPILER
#include <pmmintrin.h>
#endif
#endif
#if defined(ENABLE_MIC_INSTRUCTION_SET)
#include <immintrin.h>
#include <zmmintrin.h>
#endif
#if defined(ENABLE_NEON_INSTRUCTION_SET)
#include <arm_neon.h>
#endif
#include "NumberPolicy.h"
#include "Mask.h"
#include "Number.h"
#include "Number.Double.h"
#include "Discrete.h"
#include "Vector3.h"
#include "Constants.h"
// Load Architecture Specific Versions of Number
template <typename Vtype>
struct VTYPE_POLICY{
// const static int V_WIDTH=0;
};
template <>
struct VTYPE_POLICY<float>{
const static int V_WIDTH=1;
};
template <>
struct VTYPE_POLICY<double>{
const static int V_WIDTH=1;
};
#if defined(ENABLE_SSE_INSTRUCTION_SET)
template <>
struct VTYPE_POLICY<__m128>{
const static int V_WIDTH=4;
};
#include "arch/x86_64/Mask.SSE.h"
#include "arch/x86_64/Number.SSE.h"
#include "arch/x86_64/Discrete.SSE.h"
#if defined(ENABLE_DOUBLE_SUPPORT)
template <>
struct VTYPE_POLICY<__m128d>{
const static int V_WIDTH=2;
};
#include "arch/x86_64/Mask.SSE.Double.h"
#include "arch/x86_64/Number.SSE.Double.h"
#endif
#endif
#if defined(ENABLE_AVX_INSTRUCTION_SET)
template <>
struct VTYPE_POLICY<__m256>{
const static int V_WIDTH=8;
};
#include "arch/x86_64/Mask.AVX.h"
#include "arch/x86_64/Number.AVX.h"
#include "arch/x86_64/Discrete.AVX.h"
#if defined(ENABLE_DOUBLE_SUPPORT)
template <>
struct VTYPE_POLICY<__m256d>{
const static int V_WIDTH=4;
};
#include "arch/x86_64/Mask.AVX.Double.h"
#include "arch/x86_64/Number.AVX.Double.h"
#endif
#endif
#if defined(ENABLE_AVX512_INSTRUCTION_SET)
template <>
struct VTYPE_POLICY<__m512>{
const static int V_WIDTH=8;
};
#include "arch/x86_64/Mask.AVX512.h"
#include "arch/x86_64/Number.AVX512.h"
#include "arch/x86_64/Discrete.AVX512.h"
#if defined(ENABLE_DOUBLE_SUPPORT)
template <>
struct VTYPE_POLICY<__m512d>{
const static int V_WIDTH=8;
};
#include "arch/x86_64/Mask.AVX512.Double.h"
#include "arch/x86_64/Number.AVX512.Double.h"
#endif
#endif
#if defined(ENABLE_MIC_INSTRUCTION_SET)
template <>
struct VTYPE_POLICY<__m512>{
const static int V_WIDTH=16;
};
#include "arch/mic/Mask.MIC.h"
#include "arch/mic/Number.MIC.h"
#include "arch/mic/Discrete.MIC.h"
#endif
#if defined(ENABLE_NEON_INSTRUCTION_SET)
template <>
struct VTYPE_POLICY<float32x4_t>{
const static int V_WIDTH=4;
};
#include "arch/arm/Mask.NEON.h"
#include "arch/arm/Number.NEON.h"
#include "arch/arm/Discrete.NEON.h"
#endif
// Define Architecture Specific Helper Macros and Miscellanious
#if defined(ENABLE_SSE_INSTRUCTION_SET) || defined(ENABLE_AVX_INSTRUCTION_SET) || defined(ENABLE_AVX512_INSTRUCTION_SET)
#define KERNEL_MEM_ALIGN __declspec(align(64))
#else
#define KERNEL_MEM_ALIGN
#endif
// Define this to switch to non-augmented material formulas
#define USE_NONMIXED_FORMULAS
struct COROTATED_TAG;
struct NEOHOOKEAN_TAG;
struct BIPHASIC_TAG;
namespace nm_biphasic {
extern float *biphasic_threshold;
extern float *biphasic_factor;
//BUILD_CONSTANT( biphasic_threshold, 1.07f );
//BUILD_CONSTANT( biphasic_factor, 1e4);
}
template <class T, int width>
struct widetype{
typedef T type[width];
};
template <class T>
struct widetype<T,1>{
typedef T type;
};
#define WIDETYPE(TYPE,WIDTH) widetype<TYPE, WIDTH>::type
#define VWIDTH(TYPE) VTYPE_POLICY<TYPE>::V_WIDTH
#define INSTANCE_KERNEL_SCALAR_FLOAT(KERNEL,DATA_WIDTH) template void KERNEL<float,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#define INSTANCE_KERNEL_SCALAR_DOUBLE(KERNEL,DATA_WIDTH) template void KERNEL<double,WIDETYPE(double,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#define INSTANCE_KERNEL_SIMD_FLOAT(KERNEL,DATA_WIDTH) template void KERNEL<float,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#ifdef ENABLE_SSE_INSTRUCTION_SET
#define INSTANCE_KERNEL_SIMD_SSE(KERNEL,DATA_WIDTH) template void KERNEL<__m128,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#if defined(ENABLE_DOUBLE_SUPPORT)
#define INSTANCE_KERNEL_SIMD_SSE_DOUBLE(KERNEL,DATA_WIDTH) template void KERNEL<__m128d,WIDETYPE(double,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_SIMD_SSE_DOUBLE(KERNEL,DATA_WIDTH)
#endif
#else
#define INSTANCE_KERNEL_SIMD_SSE(KERNEL,DATA_WIDTH)
#define INSTANCE_KERNEL_SIMD_SSE_DOUBLE(KERNEL,DATA_WIDTH)
#endif
#ifdef ENABLE_AVX_INSTRUCTION_SET
#define INSTANCE_KERNEL_SIMD_AVX(KERNEL,DATA_WIDTH) template void KERNEL<__m256,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#if defined(ENABLE_DOUBLE_SUPPORT)
#define INSTANCE_KERNEL_SIMD_AVX_DOUBLE(KERNEL,DATA_WIDTH) template void KERNEL<__m256d,WIDETYPE(double,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_SIMD_AVX_DOUBLE(KERNEL,DATA_WIDTH)
#endif
#else
#define INSTANCE_KERNEL_SIMD_AVX(KERNEL,DATA_WIDTH)
#define INSTANCE_KERNEL_SIMD_AVX_DOUBLE(KERNEL,DATA_WIDTH)
#endif
#ifdef ENABLE_AVX512_INSTRUCTION_SET
#define INSTANCE_KERNEL_SIMD_AVX512(KERNEL,DATA_WIDTH) template void KERNEL<__m512,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#if defined(ENABLE_DOUBLE_SUPPORT)
#define INSTANCE_KERNEL_SIMD_AVX512_DOUBLE(KERNEL,DATA_WIDTH) template void KERNEL<__m512d,WIDETYPE(double,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_SIMD_AVX512_DOUBLE(KERNEL,DATA_WIDTH)
#endif
#else
#define INSTANCE_KERNEL_SIMD_AVX512(KERNEL,DATA_WIDTH)
#define INSTANCE_KERNEL_SIMD_AVX512_DOUBLE(KERNEL,DATA_WIDTH)
#endif
#ifdef ENABLE_MIC_INSTRUCTION_SET
#define INSTANCE_KERNEL_SIMD_MIC(KERNEL,DATA_WIDTH) template void KERNEL<__m512,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_SIMD_MIC(KERNEL,DATA_WIDTH)
#endif
#ifdef ENABLE_NEON_INSTRUCTION_SET
#define INSTANCE_KERNEL_SIMD_NEON(KERNEL,DATA_WIDTH) template void KERNEL<float32x4_t,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_SIMD_NEON(KERNEL,DATA_WIDTH)
#endif
#define INSTANCE_KERNEL( KERNEL ) \
INSTANCE_KERNEL_SCALAR_FLOAT( KERNEL, 1) \
INSTANCE_KERNEL_SIMD_FLOAT( KERNEL, 4) \
INSTANCE_KERNEL_SIMD_FLOAT( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_FLOAT( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_SSE( KERNEL, 4) \
INSTANCE_KERNEL_SIMD_SSE( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_SSE( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_AVX( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_AVX( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_AVX512( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_MIC( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_NEON( KERNEL, 4) \
INSTANCE_KERNEL_SIMD_NEON( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_NEON( KERNEL, 16)
#define INSTANCE_KERNEL_DOUBLE( KERNEL ) \
INSTANCE_KERNEL_SCALAR_DOUBLE( KERNEL, 1) \
INSTANCE_KERNEL_SIMD_SSE_DOUBLE( KERNEL, 4) \
INSTANCE_KERNEL_SIMD_SSE_DOUBLE( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_SSE_DOUBLE( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_AVX_DOUBLE( KERNEL, 4) \
INSTANCE_KERNEL_SIMD_AVX_DOUBLE( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_AVX_DOUBLE( KERNEL, 16) \
INSTANCE_KERNEL_SIMD_AVX512_DOUBLE( KERNEL, 8) \
INSTANCE_KERNEL_SIMD_AVX512_DOUBLE( KERNEL, 16) \
#define INSTANCE_KERNEL_MATERIAL_SCALAR(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,float,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#define INSTANCE_KERNEL_MATERIAL_SIMD_FLOAT(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,float,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#ifdef ENABLE_SSE_INSTRUCTION_SET
#define INSTANCE_KERNEL_MATERIAL_SIMD_SSE(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,__m128,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_MATERIAL_SIMD_SSE(KERNEL,MATERIAL,DATA_WIDTH)
#endif
#ifdef ENABLE_AVX_INSTRUCTION_SET
#define INSTANCE_KERNEL_MATERIAL_SIMD_AVX(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,__m256,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_MATERIAL_SIMD_AVX(KERNEL,MATERIAL,DATA_WIDTH)
#endif
#ifdef ENABLE_AVX512_INSTRUCTION_SET
#define INSTANCE_KERNEL_MATERIAL_SIMD_AVX512(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,__m512,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_MATERIAL_SIMD_AVX512(KERNEL,MATERIAL,DATA_WIDTH)
#endif
#ifdef ENABLE_MIC_INSTRUCTION_SET
#define INSTANCE_KERNEL_MATERIAL_SIMD_MIC(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,__m512,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_MATERIAL_SIMD_MIC(KERNEL,MATERIAL,DATA_WIDTH)
#endif
#ifdef ENABLE_NEON_INSTRUCTION_SET
#define INSTANCE_KERNEL_MATERIAL_SIMD_NEON(KERNEL,MATERIAL,DATA_WIDTH) template void KERNEL<MATERIAL,float32x4_t,WIDETYPE(float,DATA_WIDTH),WIDETYPE(int,DATA_WIDTH)>::Run( INSTANCE_KERNEL_ ## KERNEL(DATA_WIDTH) );
#else
#define INSTANCE_KERNEL_MATERIAL_SIMD_NEON(KERNEL,MATERIAL,DATA_WIDTH)
#endif
#define INSTANCE_KERNEL_MATERIAL( KERNEL, MATERIAL) \
INSTANCE_KERNEL_MATERIAL_SCALAR( KERNEL, MATERIAL, 1) \
INSTANCE_KERNEL_MATERIAL_SIMD_FLOAT( KERNEL, MATERIAL, 4) \
INSTANCE_KERNEL_MATERIAL_SIMD_FLOAT( KERNEL, MATERIAL, 8) \
INSTANCE_KERNEL_MATERIAL_SIMD_FLOAT( KERNEL, MATERIAL, 16) \
INSTANCE_KERNEL_MATERIAL_SIMD_SSE( KERNEL, MATERIAL, 4) \
INSTANCE_KERNEL_MATERIAL_SIMD_SSE( KERNEL, MATERIAL, 8) \
INSTANCE_KERNEL_MATERIAL_SIMD_SSE( KERNEL, MATERIAL, 16) \
INSTANCE_KERNEL_MATERIAL_SIMD_AVX( KERNEL, MATERIAL, 8) \
INSTANCE_KERNEL_MATERIAL_SIMD_AVX( KERNEL, MATERIAL, 16) \
INSTANCE_KERNEL_MATERIAL_SIMD_AVX512( KERNEL, MATERIAL, 16) \
INSTANCE_KERNEL_MATERIAL_SIMD_MIC( KERNEL, MATERIAL, 16) \
INSTANCE_KERNEL_MATERIAL_SIMD_NEON( KERNEL, MATERIAL, 4) \
INSTANCE_KERNEL_MATERIAL_SIMD_NEON( KERNEL, MATERIAL, 8) \
INSTANCE_KERNEL_MATERIAL_SIMD_NEON( KERNEL, MATERIAL, 16)
#endif
|
36dd6ad8fda76f6f19ba1c018c9009f7c3385c6b
|
08688f4613f7961462696936a1720bbd87680607
|
/SaldaniaTp2/Final.cpp
|
408a7bf213373a8414a53670a772f671b5707f80
|
[] |
no_license
|
vloxomire/TrabajosPracticosCPP
|
17a453b990cd5d62f5d96d365f9843205396eae4
|
cfeddbeefd1eb47db56657d84e03b7e37522ef4d
|
refs/heads/master
| 2022-07-04T20:13:47.149872
| 2020-05-17T21:37:38
| 2020-05-17T21:37:38
| 264,177,427
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,854
|
cpp
|
Final.cpp
|
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
float vida = 100.0f, inicialVida = 100.0f, inicialEscudo = 50.0f, escudo = 50.0f, cura = 0;
int powerUp = 0;
int damagePlayer = 35.0f;
int oro = 0, item, menus = 0;
int valorItem = 0;
int numRan = 0, seleccion = 0;
int aux = 0;
int restoDanioEne = 0;
int enemyRandom = 0;
srand(time(NULL));
enum class MENU { COMBATIR = 1, RETIRARSE, SHOP, GANARELJUEGO };
MENU menu = MENU::COMBATIR;
enum class OBJECT { POTION = 1, SHIELD, SCROLL };
OBJECT object = OBJECT::POTION;
enum class ENEMYTYPE { WEAK = 1, HARD };
ENEMYTYPE enemytype = ENEMYTYPE::WEAK;
enum class SHIELD { ACTIVE = 1, DESACTIVE };
SHIELD shield = SHIELD::ACTIVE;
//Enemigos
//weak enemy
int weakEnemyHP = 50;
int weakEnemyD = 15;
int goldWeakE = 500;
//Hard enemy
int hardEnemyHP = 100;
int hardEnemyD = 20;
int goldHardE = 1000;
int enemyDamage;
int enemyGold;
int enemyLife;
//Combate
int contador = 0;
std::cout << "Combate" << std::endl;
std::cout << "1-Combatir/2-Retirarse" << std::endl;
do {
if (oro >= 1500) {
std::cout << "1-Combatir/2-Ganar el juego/3-Shop" << std::endl;
}
else {
if (contador > 1) {
std::cout << "1-Combatir/2-Retirarse/3-Shop" << std::endl;
}
}
//generador de tipo de enemigo
enemyRandom = rand() % (3 - 1) + 1;
enemytype = (ENEMYTYPE)enemyRandom;
std::cout << "Enemigo encontrado ";
switch (enemytype)
{
case ENEMYTYPE::WEAK:
std::cout << "Enemigo Debil, su recompensa es de " << goldWeakE << std::endl;
enemyLife = weakEnemyHP;
enemyDamage = weakEnemyD;
enemyGold = goldWeakE;
break;
case ENEMYTYPE::HARD:
std::cout << "Enemigo Fuerte, su recompensa es de " << goldHardE << std::endl;
enemyLife = hardEnemyHP;
enemyDamage = hardEnemyD;
enemyGold = goldHardE;
break;
}
std::cin >> seleccion;
menu = (MENU)seleccion;
switch (menu)
{
case MENU::COMBATIR:
while (enemyLife > 0 && vida > 0)
{
system("pause");
system("cls");
contador++;
numRan = rand() % (51 - 1) + 1;
damagePlayer = numRan;
std::cout << "Turno " << contador << std::endl;
escudo -= enemyDamage;
if (escudo <= 0) {
aux = 2;
shield = (SHIELD)aux;
}
else {
aux = 1;
shield = (SHIELD)aux;
}
switch (shield)
{
case SHIELD::ACTIVE:
restoDanioEne = escudo - enemyDamage;
vida -= restoDanioEne;
break;
case SHIELD::DESACTIVE:
vida = vida - enemyDamage;
break;
default:
break;
}
enemyLife -= damagePlayer;
std::cout << "Jugador: " << vida << " /Escudo:" << escudo << " /Danio hecho:" << damagePlayer
<< "/ Enemigo: " << enemyLife << std::endl;
}
if (vida <= 0 && enemyLife <= 0) {
std::cout << "Empate" << std::endl;
std::cout << "Perdio el juego" << std::endl;
return 0;
}
else {
if (vida > enemyLife) {
oro += enemyGold;
std::cout << "gano el jugador" << oro << " Oro" << std::endl;
}
else {
std::cout << "gano el enemigo" << std::endl;
std::cout << "Perdio el juego" << std::endl;
return 0;
}
}
break;
case MENU::RETIRARSE:
std::cout << "Se retira del juego";
break;
case MENU::SHOP:
std::cout << "1-Posicion de vida/2-Reparar armadura/3-Scroll de danio" << std::endl;
std::cout << "vida " << vida << " escudo " << escudo << " danio " << damagePlayer << std::endl;
std::cin >> item;
object = (OBJECT)item;
valorItem = rand() % (3 - 1) + 1;
if (valorItem == 1) {
valorItem = 30 + 15;
}
else
{
valorItem = 30 - 15;
}
switch (object) {
case OBJECT::POTION:
std::cout << "Vida actual " << vida << std::endl;
cura = 30;
std::cout << "1-Posicion de vida...\n cura" << cura << " cantidad de vida" << valorItem << " $" << std::endl;
oro -= valorItem;
if ((vida + cura) > inicialVida) {
vida = inicialVida;
std::cout << "Vida actual " << vida << std::endl;
}
else {
vida += cura;
std::cout << "Vida actual " << vida << std::endl;
}
break;
case OBJECT::SHIELD:
std::cout << "2-Reparar armadura...\n restablece nuestro escudo" << std::endl;
std::cout << valorItem << "$" << std::endl;
oro -= valorItem;
if (escudo < inicialEscudo) {
escudo = inicialEscudo;
}
std::cout << " escudo " << escudo << std::endl;
break;
case OBJECT::SCROLL:
std::cout << "3-Scroll de danio...\n Permite subir el danio entre 1-5" << std::endl;
std::cout << valorItem << "$";
oro -= valorItem;
powerUp = rand() % (6 - 1) + 1;
damagePlayer += powerUp;
std::cout << " danio " << damagePlayer << std::endl;
break;
}
break;
case MENU::GANARELJUEGO:
break;
default:
break;
}
} while (seleccion != 2 && seleccion != 4);
}
|
4dce213a6856171321d16697b7fada96799251b9
|
0eff74b05b60098333ad66cf801bdd93becc9ea4
|
/second/download/CMake/CMake-gumtree/Kitware_CMake_old_new_new_log_1541.cpp
|
5cc82916c342a60c6fe20d2abaf2c2b3643e80e8
|
[] |
no_license
|
niuxu18/logTracker-old
|
97543445ea7e414ed40bdc681239365d33418975
|
f2b060f13a0295387fe02187543db124916eb446
|
refs/heads/master
| 2021-09-13T21:39:37.686481
| 2017-12-11T03:36:34
| 2017-12-11T03:36:34
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 198
|
cpp
|
Kitware_CMake_old_new_new_log_1541.cpp
|
msg << "FilesDiffer failed to read files (allocated: "
<< statSource.st_size << ", read source: " << finSource.gcount()
<< ", read dest: " << finDestination.gcount() << std::ends;
|
cb4266691260b31752faeba80d3bcc67b969c3eb
|
20be2e5541b10a2f570ea5f843da61ef04e29442
|
/hyperon_1_0_1/hyperon/storage/ini/ini_file.h
|
af4dcfc0cbd857ded24589d94ee1633d6ff49d4f
|
[] |
no_license
|
barby1138/fridmon
|
e3925530f1ba402e7ad843219056fa015b2dc8c5
|
a1e0583b10a4db1a68cb00cdeabb61f982803bfb
|
refs/heads/master
| 2020-03-30T12:04:18.781879
| 2020-02-29T09:19:44
| 2020-02-29T09:19:44
| 151,206,729
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,059
|
h
|
ini_file.h
|
// ini_file.h: interface for the ini_file class.
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// The Hyperon Library
// Copyright (c) 2004-2005 by Library Dream Team (Oli Tsisaruk, Serge Gaziev)
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// Authors make no representations about the suitability of this software for
// any purpose. It is provided "as is" without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Redesigned from Todd Davis's original source code located on
// http://www.codeproject.com/file/Cini_file.asp.
////////////////////////////////////////////////////////////////////////////////
#ifndef _HYPERON_INI_FILE_H_
#define _HYPERON_INI_FILE_H_
#include <quark/config.h>
namespace hyperon
{
//////////////////////////////////////////////////
// class ini_section_exception
//
class ini_section_exception : public quark::pruntime_error
{
public:
ini_section_exception(const char* name, const char* descr);
};
//////////////////////////////////////////////////
// class ini_record
//
//! INI File Value
/*!
*/
class ini_record
{
public:
ini_record(const quark::pstring& inValue = "", const quark::pstring& inComments = "")
: value(inValue),
comments(inComments)
{
}
quark::pstring comments;
quark::pstring value;
};
//////////////////////////////////////////////////
// class ini_section
//
//! INI File Section
/*!
*/
class ini_section
{
public:
typedef quark::pmap<quark::pstring, ini_record> records_t;
public:
ini_section();
ini_section(const quark::pstring& header, const quark::pstring& comments);
const char* getName() const { return _name.c_str(); }
// TODO: redesign
void addValue(const quark::pstring& record, const quark::pstring& comments);
const quark::pstring getValue(const quark::pstring& key) const;
const records_t& getRecords() const;
private:
records_t _records;
quark::pstring _name;
quark::pstring _comments;
};
//////////////////////////////////////////////////
// class ini_file
//
//! INI File Parser
/*!
Parses INI file and provides access to sections and values
*/
class ini_file
{
public:
typedef quark::pmap<quark::pstring, ini_section> sections_t;
public:
ini_file();
~ini_file();
bool load(const quark::pstring& file);
const sections_t& getSections() const;
// TODO: add needed accessors
private:
sections_t _sections;
quark::pstring _fileName;
};
} // namespace hyperon
#endif // _HYPERON_INI_FILE_H_
|
d4e231cec8cbe5a223a6c69d5584e01ac0297329
|
ec80c341817ea3ef219b4c93539513fcce49942f
|
/core/parameters/evaluable.cc
|
4f45317213e50b30df9f0387ad3e215fe3a1090d
|
[
"MIT"
] |
permissive
|
gnafit/gna
|
b24182b12693dfe191aa182daed0a13cfbecf764
|
03063f66a1e51b0392562d4b9afac31f956a3c3d
|
refs/heads/master
| 2023-09-01T22:04:34.550178
| 2023-08-18T11:24:45
| 2023-08-18T11:24:45
| 174,980,356
| 5
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 134
|
cc
|
evaluable.cc
|
#include "evaluable.hh"
template class evaluable<double>;
#ifdef PROVIDE_SINGLE_PRECISION
template class evaluable<float>;
#endif
|
0e22c88c98fa119afb532f14d072a6b2b57406ae
|
129ccca0ef7febc8775ccaacbd2fcd8347adf20d
|
/SinglePendulum/pendulum.cpp
|
cd6d1f3438829d4109a4e64ce4377c3dcdeb0e4e
|
[
"MIT"
] |
permissive
|
philj56/robot-swing
|
8798ccfeee448933a1880f7c5bedfbdcd66c7dc7
|
eb2527c9dabdb02dd7e4a8bb7240417479d50b1d
|
refs/heads/master
| 2021-01-19T03:04:01.005485
| 2016-08-01T15:03:23
| 2016-08-01T15:03:23
| 49,964,467
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,133
|
cpp
|
pendulum.cpp
|
/* Simple damped-driven pendulum solver
*/
#include <iomanip>
#include <iostream>
#include <fstream>
#include <cmath>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_odeiv.h>
const int columnWidth = 20; // Width of output columns
const int precision = 10; // Decimal places to output
const double m = 5.2; // Mass of pendulum
const double g = -9.81; // g
const double l = 2; // Length of pendulum
const double A = 0.5; // Amplitude of driving force
const double wd = 1; // Angular frequency of driving force
const double b = 0.5; // Damping coefficient
const int dimension = 2; // Dimension of system
int PrimeFuncGSL(double t, const double y[], double dydt[], void* params); // The derivative of theta and w
int main()
{
double epsAbs = 1e-12; // Maximum desired absolute error
double epsRel = 0; // Maximum desired relative error
double y[dimension] = {1, 0}; // Array of [theta, w]
double t = 0; // Time
double tFinal = 60; // Time to end simulation
double stepSize = 0.1; // Initial step size for RK4
gsl_odeiv_system GSLsystem = {PrimeFuncGSL, NULL, dimension, NULL}; // The GSL system
gsl_odeiv_step* StepFunc = gsl_odeiv_step_alloc(gsl_odeiv_step_rkf45, dimension); // The GSL stepping function
gsl_odeiv_control* control = gsl_odeiv_control_standard_new(epsAbs, epsRel, 1, 0); // The control function for adaptive step sizing
gsl_odeiv_evolve* evolve = gsl_odeiv_evolve_alloc(dimension); // The workspace to evolve the system with adaptive step sizing
// Main loop
while (t < tFinal)
{
// Check for Runge-Kutta success
if (gsl_odeiv_evolve_apply(evolve, control, StepFunc, &GSLsystem, &t, tFinal, &stepSize, y) != GSL_SUCCESS)
{
break;
}
// Output data
std::cout << std::setprecision(precision)
<< std::setw(columnWidth) << t
<< std::setw(columnWidth) << y[0]
<< std::setw(columnWidth) << evolve->yerr[0]
<< std::endl;
}
}
// Derivatives of theta and w
int PrimeFuncGSL(double t, const double y[], double dydt[], void* params)
{
dydt[0] = y[1];
dydt[1] = -(g / l) * sin(y[0]) + (A * cos(wd * t) - b * y[1]) / (m * l * l);
return GSL_SUCCESS;
}
|
f91b2b0789a58710dd7ab06b28966d11f2f4d0f4
|
16d6f0160cb776b4cb8ef69ac6ce4e0431fa00a8
|
/2stackForqueue/stackForQueue.cpp
|
d69d783550476dc4302a31fc0cf47eac23ae547e
|
[] |
no_license
|
bingtaoli/algo
|
efab7096fa28ccda92b316a4a1fbb7057d0f3293
|
6f3b99dcdc091fcf58ac40459db2b615e271cb6a
|
refs/heads/master
| 2021-01-22T02:24:37.279206
| 2020-02-08T08:17:25
| 2020-02-08T08:17:25
| 92,359,116
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 439
|
cpp
|
stackForQueue.cpp
|
#include "stackForQueue.h"
int StackForQueue::pop()
{
if (0 != s2.size())
{
int value = s2.top();
s2.pop();
return value;
}
//s1 to s2
while ( !s1.empty() )
{
int value = s1.top();
s1.pop();
s2.push(value);
}
if (0 != s2.size())
{
int value = s2.top();
s2.pop();
return value;
}
}
void StackForQueue::push(int value)
{
s1.push(value);
return ;
}
int StackForQueue::size()
{
return s1.size() + s2.size();
}
|
2c1378af233332a1e5d7cb26af1c899fc119fd27
|
266e641df3f6ee7c2de19fc60c941532c1f5c05d
|
/main.cpp
|
29d5bf6d9e923656e3530c414256a5086175322f
|
[] |
no_license
|
pranavmodx/modlang-old
|
9ec75070884a062b6b41a263b555ecca73c005dd
|
3d3b5824b8cb5d8582671c94d8a475a38d257e12
|
refs/heads/main
| 2023-01-30T15:14:34.552202
| 2020-12-12T14:41:51
| 2020-12-12T15:12:19
| 317,954,329
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 670
|
cpp
|
main.cpp
|
#include <iostream>
#include <assert.h>
#include <string.h>
#include <vector>
#include <fstream>
#include "./header/lexer.hpp"
std::string read_file(const std::string &file_name) {
std::ifstream ifs(file_name.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
std::ifstream::pos_type file_size = ifs.tellg();
ifs.seekg(0, std::ios::beg);
std::vector<char> source_code(file_size);
ifs.read(source_code.data(), file_size);
return std::string(source_code.data(), file_size);
}
int main(int argc, char* argv[]) {
assert(argc > 1);
std::string filename(argv[1]);
std::string input = read_file(filename);
Lexer lexer;
lexer.New(input);
}
|
32437c53becf0327c001eaa5c1419548ce755f39
|
dbc5fd6f0b741d07aca08cff31fe88d2f62e8483
|
/tools/clang/test/zapcc/multi/weakref/file2.cpp
|
4009257634e98f7cf236862f9e19d9c9859c3e6b
|
[
"LicenseRef-scancode-unknown-license-reference",
"NCSA"
] |
permissive
|
yrnkrn/zapcc
|
647246a2ed860f73adb49fa1bd21333d972ff76b
|
c6a8aa30006d997eff0d60fd37b0e62b8aa0ea50
|
refs/heads/master
| 2023-03-08T22:55:12.842122
| 2020-07-21T10:21:59
| 2020-07-21T10:21:59
| 137,340,494
| 1,255
| 88
|
NOASSERTION
| 2020-07-21T10:22:01
| 2018-06-14T10:00:31
|
C++
|
UTF-8
|
C++
| false
| false
| 56
|
cpp
|
file2.cpp
|
#include "f.h"
void foo2() { __gthrw_pthread_equal(); }
|
628226d41ce5969fe3d01952acb61efc21c1a552
|
1cd995744a830f70b068b3ff925e06188d94e1c3
|
/tests/rom/utils/utils_eigen.hpp
|
cac7422ef3544716c6e0738c503944e1c3f5e3a1
|
[
"BSD-3-Clause"
] |
permissive
|
zeta1999/pressio
|
41dcf4ac6787f0463b4e7f4820e801ce1ee677a4
|
0cc57a071fb5e0719462c259de2565d9bea8144c
|
refs/heads/master
| 2022-12-27T11:31:52.258613
| 2020-09-14T15:18:15
| 2020-09-14T15:18:15
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,038
|
hpp
|
utils_eigen.hpp
|
#ifndef ROM_TEST_UTILS_EIGEN_HPP_
#define ROM_TEST_UTILS_EIGEN_HPP_
#include "pressio_utils.hpp"
namespace pressio{ namespace rom{ namespace test{ namespace eigen{
template <typename T = std::size_t>
auto convertFromVVecToMultiVec(
const std::vector<std::vector<double>> & A0,
T nrows, T ncols)
-> pressio::containers::MultiVector<Eigen::MatrixXd>{
using eig_mat = Eigen::MatrixXd;
pressio::containers::MultiVector<eig_mat> ADW(nrows, ncols);
for (T i=0; i<nrows; i++){
for (T j=0; j<ncols; j++)
ADW(i,j) = A0[i][j];
}
return ADW;
}
template <typename T = std::size_t>
auto readBasis(std::string filename, T romSize, T numCell)
->pressio::containers::MultiVector<Eigen::MatrixXd>
{
std::vector<std::vector<double>> A0;
::pressio::utils::readAsciiMatrixStdVecVec(filename, A0, romSize);
// read basis into a MultiVector
auto phi = convertFromVVecToMultiVec(A0, numCell, romSize);
// phi.data()->Print(std::cout);
return phi;
}
}}}}// end namespace pressio::rom::test::eigen
#endif
|
f72f9b653bcbf2b1a44cd792f4d219c3a7e186f3
|
f4dc1073def4c95a19d4183475405c439cfc0aff
|
/Source/Core/AresPerlinNoise.cpp
|
a1d30a72a3b3b4bd2c520aa15dbfbc393adddba9
|
[] |
no_license
|
timi-liuliang/aresengine
|
9cf74e7137bb11cd8475852b8e4c9d51eda62505
|
efd39c6ef482b8d50a8eeaa5009cac5d5b9f41ee
|
refs/heads/master
| 2020-04-15T15:06:41.726469
| 2019-01-09T05:09:35
| 2019-01-09T05:09:35
| 164,779,995
| 1
| 0
| null | null | null | null |
GB18030
|
C++
| false
| false
| 2,488
|
cpp
|
AresPerlinNoise.cpp
|
#include <Core/AresPerlinNoise.h>
namespace Ares
{
// 构造函数
CPerlinNoise::CPerlinNoise()
{
SetUp();
}
// 设置
void CPerlinNoise::SetUp()
{
float stepDegree = 2 * PI / EM_TABLE_SIZE;
float degree = 0.0f;
srand(GetTickCount());
for (int i=0; i<EM_TABLE_SIZE; i++)
{
// sinA的平方 + cosA的平方 = 1; 以确保为单位向量
m_vTable[i].x = (float)sin(degree);
m_vTable[i].y = (float)cos(degree);
degree += stepDegree;
// 取随机数的前8位
m_lut[i] = rand() & EM_TABLE_MASK;
}
}
// 噪音函数
float CPerlinNoise::Noise(int x, int y, float scale)
{
return Noise( (float)x, (float)y, scale);
}
float CPerlinNoise::Noise(float x, float y, float scale)
{
Vector2 pos( x*scale, y*scale);
// 求得象素所在格子的右上角左下角坐标
float x0 = (float)floor( pos.x);
float x1 = x0 + 1.0f;
float y0 = (float)floor( pos.y);
float y1 = y0 + 1.0f;
// 为网格的四个顶点设置随机方向单位向量
Vector2 vectorLU = *GetVec( (int)x0, (int)y0);
Vector2 vectorLD = *GetVec( (int)x0, (int)y1);
Vector2 vectorRU = *GetVec( (int)x1, (int)y0);
Vector2 vectorRD = *GetVec( (int)x1, (int)y1);
// 网格的四个顶点到象素的向量
Vector2 d0( pos.x-x0, pos.y-y0);
Vector2 d1( pos.x-x0, pos.y-y1);
Vector2 d2( pos.x-x1, pos.y-y0);
Vector2 d3( pos.x-x1, pos.y-y1);
// 求网格各顶点两向量的点积
float h0 = (d0.x * vectorLU.x) + (d0.y * vectorLU.y);
float h1 = (d1.x * vectorLD.x) + (d1.y * vectorLD.y);
float h2 = (d2.x * vectorRU.x) + (d2.y * vectorRU.y);
float h3 = (d3.x * vectorRD.x) + (d3.y * vectorRD.y);
float Sx, Sy;
//
// 柏林公式
// w = 3t*t - 2t*t*t; 快速但产生较陡峭地形
// w = 6t5 – 15t4 + 10t3; 此处使用这个
Sx = 6 * powf( d0.x, 5.0f) - 15 * powf( d0.x, 4.0f) + 10 * powf( d0.x, 3.0f);
Sy = 6 * powf( d0.y, 5.0f) - 15 * powf( d0.y, 4.0f) + 10 * powf( d0.y, 3.0f);
float avgX0 = h0 + ( Sx * (h2 - h0));
float avgX1 = h1 + ( Sx * (h3 - h1));
float result = avgX0 + ( Sy * (avgX1 - avgX0));
return result;
}
inline const Vector2* CPerlinNoise::GetVec(int x, int y) const
{
unsigned char xr = m_lut[x & EM_TABLE_MASK]; // 参数x获取的随机数
unsigned char yr = m_lut[y & EM_TABLE_MASK]; // 参数y获取的随机数
unsigned char xyr = m_lut[(xr + yr) & EM_TABLE_MASK]; // 有参数x y 共同决定的随机数(随机数必位于0-255之间)
return &m_vTable[xyr];
}
}
|
debb5816f9716191a6eb33c9d05ad9d3a2b8a1d8
|
e92a8e7ba8dbad9339ba14db9a32a772e9415ac3
|
/baekjoon/8958.cpp
|
fd741d7b883624b0fff9037cd52f19f3b85a0a8d
|
[] |
no_license
|
Lee-Jungyu/algorithm
|
ec3155a4424d97d12ab96d98f7a7f14589f8ec70
|
6a18758ba3d4ee55a6cfae33ed86258ddda9bc96
|
refs/heads/master
| 2021-08-06T15:28:06.919063
| 2021-07-14T12:49:37
| 2021-07-14T12:49:37
| 232,481,372
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 433
|
cpp
|
8958.cpp
|
#include <iostream>
#include <string>
using namespace std;
char OX[80];
int main()
{
int tc;
int sum;
string input;
scanf("%d", &tc);
while (tc--)
{
sum = 0;
cin >> input;
for (int i = 0; i < input.length(); i++)
{
OX[i] = input[i];
}
int cnt = 0;
for (int i = 0; i < input.length(); i++)
{
cnt++;
if (OX[i] == 'X') {
cnt = 0;
}
else {
sum += cnt;
}
}
printf("%d\n", sum);
}
}
|
56cf12cd6d3d5da0eb115d92257fac7e2cc3053c
|
35f345dd1b4f6be564b7753b7b45d772b59a55b9
|
/Pong/renderer.h
|
f859db790663acf9d1e499d60652cbde502f3acb
|
[] |
no_license
|
shindelus/Pong
|
42a58e7a76f4759f133ae7432827463012d3d225
|
7fca7985fdc014b2dde4605deff43ce19713f6bb
|
refs/heads/master
| 2021-05-24T12:05:50.290936
| 2020-04-27T23:54:41
| 2020-04-27T23:54:41
| 253,550,559
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 647
|
h
|
renderer.h
|
#pragma once
#include "glew/include/GL/glew.h"
#include "vertexarray.h"
#include "indexbuffer.h"
#include "shader.h"
/**
Clear all (unrelated) previous errors.
*/
//void GLClearError();
/**
Check for an error and log the error to the console.
@param function The function where the error happend
@param file The file where the error happend
@param line The line number where the error happend
@return Whether there was an error
*/
//bool GLLogCall(const char* function, const char* file, int line);
class Renderer
{
public:
void Clear() const;
void Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const;
};
|
f3ccd46e4a44006c9d8b83d4ae01669afbd89c6c
|
acf11da3a33c609c0e356057d1522fa790b34c22
|
/Livraria2.0/build-Livraria-Desktop_Qt_5_10_0_GCC_64bit-Debug/ui_mainwindow.h
|
1f6d298510d95fd879dadab85c2dc65b5d8ed181
|
[] |
no_license
|
leonarck00/Livraria
|
5fc8f33298f73d5a15bf7e408134d47e4558b11a
|
f6f58f14b65f0dd7e2cfc1ce4a4798ac1671de9c
|
refs/heads/master
| 2020-04-11T21:24:55.954392
| 2018-12-17T09:21:44
| 2018-12-17T09:21:44
| 162,104,776
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 9,146
|
h
|
ui_mainwindow.h
|
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created by: Qt User Interface Compiler version 5.10.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QLineEdit *lineEdit_Nome;
QLabel *label;
QLabel *label_2;
QLineEdit *lineEdit_codigo;
QLabel *label_3;
QLineEdit *lineEdit_Email;
QLabel *label_4;
QLineEdit *lineEdit_Telefone;
QLabel *label_5;
QLabel *label_6;
QLineEdit *lineEdit_Editora;
QLineEdit *lineEdit_Titulo;
QLineEdit *lineEdit_Autor;
QLabel *label_7;
QLabel *label_8;
QLabel *label_9;
QLineEdit *lineEdit_ISBN;
QLabel *label_10;
QLabel *label_11;
QPushButton *pushButton;
QPushButton *pushButton_2;
QPushButton *pushButton_3;
QPushButton *pushButton_4;
QTextEdit *textEdit;
QPushButton *pushButton_5;
QLabel *label_13;
QLineEdit *lineEdit_quantidade;
QMenuBar *menuBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QStringLiteral("MainWindow"));
MainWindow->resize(614, 455);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
lineEdit_Nome = new QLineEdit(centralWidget);
lineEdit_Nome->setObjectName(QStringLiteral("lineEdit_Nome"));
lineEdit_Nome->setGeometry(QRect(120, 100, 251, 21));
label = new QLabel(centralWidget);
label->setObjectName(QStringLiteral("label"));
label->setGeometry(QRect(300, 0, 51, 16));
label_2 = new QLabel(centralWidget);
label_2->setObjectName(QStringLiteral("label_2"));
label_2->setGeometry(QRect(60, 100, 51, 16));
lineEdit_codigo = new QLineEdit(centralWidget);
lineEdit_codigo->setObjectName(QStringLiteral("lineEdit_codigo"));
lineEdit_codigo->setGeometry(QRect(120, 130, 251, 21));
label_3 = new QLabel(centralWidget);
label_3->setObjectName(QStringLiteral("label_3"));
label_3->setGeometry(QRect(60, 130, 51, 16));
lineEdit_Email = new QLineEdit(centralWidget);
lineEdit_Email->setObjectName(QStringLiteral("lineEdit_Email"));
lineEdit_Email->setGeometry(QRect(120, 160, 251, 21));
label_4 = new QLabel(centralWidget);
label_4->setObjectName(QStringLiteral("label_4"));
label_4->setGeometry(QRect(60, 160, 51, 16));
lineEdit_Telefone = new QLineEdit(centralWidget);
lineEdit_Telefone->setObjectName(QStringLiteral("lineEdit_Telefone"));
lineEdit_Telefone->setGeometry(QRect(120, 190, 251, 21));
label_5 = new QLabel(centralWidget);
label_5->setObjectName(QStringLiteral("label_5"));
label_5->setGeometry(QRect(50, 190, 71, 16));
label_6 = new QLabel(centralWidget);
label_6->setObjectName(QStringLiteral("label_6"));
label_6->setGeometry(QRect(170, 70, 171, 16));
lineEdit_Editora = new QLineEdit(centralWidget);
lineEdit_Editora->setObjectName(QStringLiteral("lineEdit_Editora"));
lineEdit_Editora->setGeometry(QRect(120, 320, 251, 21));
lineEdit_Titulo = new QLineEdit(centralWidget);
lineEdit_Titulo->setObjectName(QStringLiteral("lineEdit_Titulo"));
lineEdit_Titulo->setGeometry(QRect(120, 260, 251, 21));
lineEdit_Autor = new QLineEdit(centralWidget);
lineEdit_Autor->setObjectName(QStringLiteral("lineEdit_Autor"));
lineEdit_Autor->setGeometry(QRect(120, 290, 251, 21));
label_7 = new QLabel(centralWidget);
label_7->setObjectName(QStringLiteral("label_7"));
label_7->setGeometry(QRect(70, 290, 51, 16));
label_8 = new QLabel(centralWidget);
label_8->setObjectName(QStringLiteral("label_8"));
label_8->setGeometry(QRect(70, 260, 51, 16));
label_9 = new QLabel(centralWidget);
label_9->setObjectName(QStringLiteral("label_9"));
label_9->setGeometry(QRect(60, 320, 61, 16));
lineEdit_ISBN = new QLineEdit(centralWidget);
lineEdit_ISBN->setObjectName(QStringLiteral("lineEdit_ISBN"));
lineEdit_ISBN->setGeometry(QRect(120, 350, 251, 21));
label_10 = new QLabel(centralWidget);
label_10->setObjectName(QStringLiteral("label_10"));
label_10->setGeometry(QRect(80, 350, 51, 16));
label_11 = new QLabel(centralWidget);
label_11->setObjectName(QStringLiteral("label_11"));
label_11->setGeometry(QRect(160, 230, 141, 16));
pushButton = new QPushButton(centralWidget);
pushButton->setObjectName(QStringLiteral("pushButton"));
pushButton->setGeometry(QRect(50, 30, 121, 23));
pushButton_2 = new QPushButton(centralWidget);
pushButton_2->setObjectName(QStringLiteral("pushButton_2"));
pushButton_2->setGeometry(QRect(190, 30, 121, 23));
pushButton_3 = new QPushButton(centralWidget);
pushButton_3->setObjectName(QStringLiteral("pushButton_3"));
pushButton_3->setGeometry(QRect(330, 30, 121, 23));
pushButton_4 = new QPushButton(centralWidget);
pushButton_4->setObjectName(QStringLiteral("pushButton_4"));
pushButton_4->setGeometry(QRect(470, 30, 111, 23));
textEdit = new QTextEdit(centralWidget);
textEdit->setObjectName(QStringLiteral("textEdit"));
textEdit->setGeometry(QRect(380, 100, 211, 241));
textEdit->setReadOnly(true);
pushButton_5 = new QPushButton(centralWidget);
pushButton_5->setObjectName(QStringLiteral("pushButton_5"));
pushButton_5->setGeometry(QRect(380, 350, 211, 51));
label_13 = new QLabel(centralWidget);
label_13->setObjectName(QStringLiteral("label_13"));
label_13->setGeometry(QRect(30, 380, 91, 20));
lineEdit_quantidade = new QLineEdit(centralWidget);
lineEdit_quantidade->setObjectName(QStringLiteral("lineEdit_quantidade"));
lineEdit_quantidade->setGeometry(QRect(120, 380, 251, 21));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QStringLiteral("menuBar"));
menuBar->setGeometry(QRect(0, 0, 614, 22));
MainWindow->setMenuBar(menuBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QStringLiteral("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
label->setText(QApplication::translate("MainWindow", "Livraria", nullptr));
label_2->setText(QApplication::translate("MainWindow", "Nome:", nullptr));
label_3->setText(QApplication::translate("MainWindow", "Codigo:", nullptr));
label_4->setText(QApplication::translate("MainWindow", "E-mail:", nullptr));
label_5->setText(QApplication::translate("MainWindow", "Telefone:", nullptr));
label_6->setText(QApplication::translate("MainWindow", "Informa\303\247\303\265es do usuario", nullptr));
label_7->setText(QApplication::translate("MainWindow", "Autor:", nullptr));
label_8->setText(QApplication::translate("MainWindow", "Titulo:", nullptr));
label_9->setText(QApplication::translate("MainWindow", "Editora:", nullptr));
label_10->setText(QApplication::translate("MainWindow", "ISBN:", nullptr));
label_11->setText(QApplication::translate("MainWindow", "Informa\303\247\303\265es do livro", nullptr));
pushButton->setText(QApplication::translate("MainWindow", "Cadastrar usuario", nullptr));
pushButton_2->setText(QApplication::translate("MainWindow", "Cadastrar livro", nullptr));
pushButton_3->setText(QApplication::translate("MainWindow", "Listar usuario", nullptr));
pushButton_4->setText(QApplication::translate("MainWindow", "Listar livro", nullptr));
pushButton_5->setText(QApplication::translate("MainWindow", "Confirmar", nullptr));
label_13->setText(QApplication::translate("MainWindow", "Quantidade:", nullptr));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
|
474e782c1046242c090c6f0eab1643f6fcb7df81
|
e96dead1ea358d9e524a175a75d6d13df243955c
|
/test_join_chain.cpp
|
ac99e5dcede4afce223b6405b7d815601123d2e0
|
[] |
no_license
|
peterxie/482p2
|
fbbd80926c247833eb3d8ae20e502cd9ae515ff5
|
54d9485bf895ff0af2b8f026c2cf313ab39b7d01
|
refs/heads/master
| 2021-06-25T10:52:00.458539
| 2017-09-09T15:09:16
| 2017-09-09T15:09:16
| 102,963,043
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,184
|
cpp
|
test_join_chain.cpp
|
#include<iostream>
#include "thread.h"
using namespace std;
mutex mutex1;
cv cv1;
int child_done = 0;
void child(void *a)
{
char *message = (char*) a;
mutex1.lock();
cout << "child run with message " << message << ", setting child_done = 1\n";
child_done = 1;
mutex1.unlock();
}
void parent(void *a)
{
intptr_t arg = (intptr_t) a;
mutex1.lock();
cout << "parent called with arg " << arg << endl;
mutex1.unlock();
thread t1 ((thread_startfunc_t) child, (void*) "test message");
mutex1.lock();
cout << "yielding thread\n";
mutex1.unlock();
thread::yield();
mutex1.lock();
cout << "creating second child\n";
thread t2 ((thread_startfunc_t) child, (void*) "child 2");
cout << "joining on finished child thread\n";
t1.join();
cout << "parent finishing" << endl;
mutex1.unlock();
}
void real_parent(void *a)
{
intptr_t arg = (intptr_t) a;
mutex1.lock();
cout << "real parent called with arg " << arg << endl;
mutex1.unlock();
thread t ((thread_startfunc_t) parent, (void*) 1);
cout << "joining on parent thread\n";
t.join();
return;
}
int main()
{
cpu::boot(1, (thread_startfunc_t) real_parent, (void*) 100, 0, 0, 0);
}
|
92a6b140042250b3bdddae9607fd76d2ae7fe23c
|
d502885744b7b4b8a3696af532a4aceecea5ea8d
|
/Ejercicio8.cpp
|
89b2408802bfc8082a4b55f8f681cf249c5b07b8
|
[] |
no_license
|
noeliarodriguez/eclipse
|
9baa08358accc4188a3a01fc8585413a7d8ff2bb
|
140a7591d2dcb2caa3bd07b12d4d5ae8d144e060
|
refs/heads/master
| 2021-01-11T11:00:16.009929
| 2015-09-21T19:08:03
| 2015-09-21T19:08:03
| 40,254,332
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,246
|
cpp
|
Ejercicio8.cpp
|
//============================================================================
// Name : Ejercicio8.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Dado un triángulo representado por sus lados L1, L2, L3,
// determinar e imprimir una leyenda según sea: equilátero, isósceles o escálenos.
//============================================================================
#include <iostream>
using namespace std;
int main() {
int l1,l2,l3;
int triang = 0;
int isoc = 0;
int equi = 0;
int esca = 0;
cout << "Ingrese 3 lados de un triangulo: " << endl;
cin >> l1 >> l2 >>l3;
while ((l1>0) and (l2>0) and (l3>0)){
if (l1+l2>=l3 and l2+l3>=l1 and l1+l3>=l2){
triang++;
if ((l1==l2) and (l2==l3)){
equi++;
}else{
if ((l1 != l2) and (l2!=l3) and (l1!=l3)){
esca++;
}else{
isoc++;
}
}
}else{
cout << "Datos incorrectos" << endl;
}
cout << "Ingrese 3 lados de un triangulo: " << endl;
cin >> l1 >> l2 >> l3;
}
cout << "Cantidad de triangulos ingresados: " << triang <<endl;
cout << "Cantidad de equilateros: " << equi <<endl;
cout << "cantidad de isoceles: " << isoc << endl;
cout << "Cantidad de escalenos: " << esca <<endl;
return 0;
}
|
5c6e627f28632e0bb5ccc741712e7459025170ed
|
972c428c38e47c55ebe9b6a6d479762400f14090
|
/PrueVirtual.cpp
|
1ee604fedd144f1314aee02d398b55aaaddf72f9
|
[] |
no_license
|
francliu/cplusplusAndUnix
|
0d221a9ec81589b9bd93353f0229b8651d9318b1
|
4dc24d6a2b05a48b8cac9c549f2bb18e2173cc54
|
refs/heads/master
| 2020-04-10T00:07:13.291312
| 2016-01-31T13:20:10
| 2016-01-31T13:20:10
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 914
|
cpp
|
PrueVirtual.cpp
|
/*************************************************************************
> File Name: template.cpp
> Author: 刘建飞
> Mail: liujianfei526@163.com
> Created Time: 2016年01月22日 星期五 19时52分44秒
************************************************************************/
#include<iostream>
using namespace std;
class mumble
{
public:
mumble(){
}
//virtual void f()=0;
//virtual void f()=0;
virtual ~mumble()=0;
//Test<int> m;
};
/**
//纯虚函数在类里面声明,在类外可以实现,在类里面不可以.
void mumble::f(){
cout<<"f()"<<endl;
}
*/
//纯虚析构函数必须定义
mumble::~mumble(){
cout<<"~mumble"<<endl;
}
class A:public mumble{
public:
void f()
{
//mumble::f();
cout<<333<<endl;
}
/**
~A(){
cout<<"~A"<<endl;
}
*/
};
//纯虚函数可以有函数体,
int main(){
//mumble m;a
//mumble m;
A a;
a.f();
return 0;
}
|
531b40a51b7edd923ced73f0277b6b2707507971
|
8257ab5293edaebc1321184e59dadf820fee26d1
|
/include/Vorb/RingBuffer.inl
|
4ed13703b6f2696288b1685913a4eed7ed160b3f
|
[
"MIT"
] |
permissive
|
RegrowthStudios/Vorb
|
50812d53aac605e62660b40dab45f8b6c39a7f7f
|
bd6fc2b3df672227e8302c38223fac123abcbb2f
|
refs/heads/develop
| 2021-08-18T22:38:46.417800
| 2019-10-29T12:32:45
| 2019-10-29T12:32:45
| 27,497,366
| 67
| 36
|
MIT
| 2019-10-29T12:32:46
| 2014-12-03T16:53:03
|
C++
|
UTF-8
|
C++
| false
| false
| 3,444
|
inl
|
RingBuffer.inl
|
namespace impl {
template<typename T, typename Arg1, typename... Args>
inline void moveAll(std::vector<T>& data, const size_t& i, Arg1&& v1, Args&&... values) {
data[i % data.size()] = std::move<Arg1>(v1);
moveAll(data, i + 1, values...);
}
template<typename T, typename Arg1>
inline void moveAll(std::vector<T>& data, const size_t& i, Arg1&& v1) {
data[i % data.size()] = std::move<Arg1>(v1);
}
template<typename... T>
inline size_t numArgs(T... ) {
const int n = sizeof...(T);
return n;
}
inline size_t numArgs() {
return 0;
}
}
template<typename T>
vorb::ring_buffer<T>::ring_buffer(const size_t& capacity) :
m_data(capacity) {
if (capacity == 0) throw std::runtime_error("Capacity must be non-zero");
}
template<typename T>
const size_t& vorb::ring_buffer<T>::size() const {
return m_elements;
}
template<typename T>
size_t vorb::ring_buffer<T>::capacity() const {
return m_data.capacity();
}
template<typename T>
void vorb::ring_buffer<T>::resize(const size_t& s) {
if (s == 0) throw std::runtime_error("Capacity must be non-zero");
// Don't need to resize
if (s == m_data.size()) return;
// If size if smaller than number of elements, faux-pop elements
if (s < m_elements) {
m_tail += m_elements - s;
m_tail %= m_data.capacity();
m_elements = s;
}
// Allocate new vector
std::vector<T> copy(s);
size_t i = 0;
// Check for a split buffer
if (m_tail > m_head || m_elements > 0) {
// Pop from tail to end
while (m_tail < m_data.capacity()) {
copy[i++] = m_data[m_tail++];
}
m_tail = 0;
}
// Pop from tail to head
while (m_tail < m_head) {
copy[i++] = m_data[m_tail++];
}
// Swap contents
m_data.swap(copy);
// Update new head and tail
m_head = m_elements;
m_tail = 0;
}
template<typename T>
void vorb::ring_buffer<T>::clear() {
// Faux-clear
m_head = 0;
m_tail = 0;
m_elements = 0;
}
template<typename T>
const T& vorb::ring_buffer<T>::front() const {
return m_data[m_tail];
}
template<typename T>
T& vorb::ring_buffer<T>::front() {
return m_data[m_tail];
}
template<typename T>
const T& vorb::ring_buffer<T>::back() const {
size_t i = m_head + (m_data.capacity() - 1);
return m_data[i % m_data.capacity()];
}
template<typename T>
T& vorb::ring_buffer<T>::back() {
size_t i = m_head + (m_data.capacity() - 1);
return m_data[i % m_data.capacity()];
}
template<typename T>
const T& vorb::ring_buffer<T>::at(const size_t& i) const {
size_t ind = m_tail + i;
return m_data[ind % m_data.capacity()];
}
template<typename T>
T& vorb::ring_buffer<T>::at(const size_t& i) {
size_t ind = m_tail + i;
return m_data[ind % m_data.capacity()];
}
template<typename T>
void vorb::ring_buffer<T>::pop() {
if (m_elements == 0) return;
m_elements--;
m_tail++;
m_tail %= m_data.capacity();
}
template<typename T>
template<typename... Args>
bool vorb::ring_buffer<T>::push(Args&&... values) {
size_t numElements = impl::numArgs(values...);
if (m_elements + numElements > m_data.capacity()) return false;
m_elements += numElements;
// Add data at head
impl::moveAll(m_data, m_head, values...);
// Move head
m_head += numElements;
m_head %= m_data.capacity();
return true;
}
|
3f6146c61562d85566cf9c1efad129d56bb74826
|
c0c44b30d6a9fd5896fd3dce703c98764c0c447f
|
/cpp/Targets/MapLibNG/WindowsMobile/include/WinMobileNativeTextInterface.h
|
d940ff6025519520d5198dcc23a7c5f70fdbc5cc
|
[
"BSD-3-Clause"
] |
permissive
|
wayfinder/Wayfinder-CppCore-v2
|
59d703b3a9fdf4a67f9b75fbbf4474933aeda7bf
|
f1d41905bf7523351bc0a1a6b08d04b06c533bd4
|
refs/heads/master
| 2020-05-19T15:54:41.035880
| 2010-06-29T11:56:03
| 2010-06-29T11:56:03
| 744,294
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,243
|
h
|
WinMobileNativeTextInterface.h
|
/*
Copyright (c) 1999 - 2010, Vodafone Group Services Ltd
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the Vodafone Group Services Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _WINMOBILENATIVETEXTINTERFACE_H_
#define _WINMOBILENATIVETEXTINTERFACE_H_
#include "NativeTextInterface.h"
#include "BitMapLoader.h"
class WinMobileNativeTextInterface : public NativeTextInterface,
public BitMapTextLoader {
public:
WinMobileNativeTextInterface();
/**
* @see NativeTextInterface::getStringAsRectangles
*/
virtual int getStringAsRectangles(
vector<isab::Rectangle>& boxes,
const STRING& text,
const MC2Point& center,
int startIdx,
int nbrChars,
float angle );
/**
* @see NativeTextInterface::getStringAsRectangle
*/
virtual isab::Rectangle getStringAsRectangle( const STRING& text,
const MC2Point& point,
int startIdx = 0,
int nbrChars = -1,
float angle = 0.0 );
/**
* @see NativeTextInterface::setFont
*/
virtual void setFont( const STRING& fontName, int size );
/**
* @see NativeTextInterface::getStringLength
*/
virtual int getStringLength( const STRING& text );
/**
* @see NativeTextInterface::createString
*/
virtual STRING* createString( const char* text );
/**
* @see NativeTextInterface::deleteString
*/
virtual void deleteString( STRING* text );
/**
* @see BitMapLoader::load
*/
virtual int load( RGBA32BitMap& bitMap );
/**
* Get if the text rendering direction is left to right
* or not (arabic, hebrew is right to left) for the
* specified text.
* Default implementation returns true.
*/
virtual bool textDirectionLeftToRight( const STRING& text ) {
return true;
}
/**
* Creates a platform specific font using the specification fontSpec.
*/
virtual isab::Font* createFont(WFAPI::FontSpec* fontSpec);
/**
* Deallocates a platform specific font.
*/
virtual void deleteFont(isab::Font* font);
private:
/**
* Convert the desired part of the utf8 string to unicode.
*
* @param text The utf8 string.
* @param startIdx The index of the first char of the string.
* @param nbrChars The number of chars in the string.
* If -1, use max length of the string.
* @param uniStr Prealloced unicode string to place result in.
* @param uniStrLen The length of the prealloced unicode
* string.
* @return Number of characters in the returned string.
*/
int utf8ToUnicode( const STRING& text,
int startIdx,
int nbrChars,
wchar_t* uniStr,
int uniStrLen );
/**
* Creates a new GDI font with the specified angle.
*
* @param angle The wanted angle of the font.
*
* @return The created font.
*/
HFONT createFont( float angle );
/**
* Creates a rectangle which encloses the rectangle obtained
* by rotating the supplied rectangle defined by the two points.
*/
isab::Rectangle rotatedRect(int x1, int y1,
int x2, int y2,
float angle);
/* the current font */
HFONT m_curFont;
int32 m_fontWidth, m_fontHeight;
/* for caching fonts */
STRING m_curFontName;
int32 m_curFontSize;
LOGFONT m_fontData;
TEXTMETRIC m_textMetrics;
HDC m_dc;
};
#endif /* _WINMOBILENATIVETEXTINTERFACE_H_ */
|
c26ae6cc65c742e50f28eaa75e7d2fa1050ac3e2
|
4269cd72884e1ae157527c7bf06bfac2ace60e6b
|
/sqlparser/libsqlparser/src/SelectItem.cpp
|
833acc31b2cff1c39cb17efeb35ada347d2b4828
|
[] |
no_license
|
Raphael2017/sqlparsernxl
|
14943eb10d4af3e1d62a2bf07ae9a8a53a9a6125
|
5b25ccff72eab198674d18a60ed4565c65bc9e9e
|
refs/heads/master
| 2020-04-07T23:35:58.187820
| 2019-08-16T05:53:35
| 2019-08-16T05:53:35
| 158,818,649
| 5
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 110
|
cpp
|
SelectItem.cpp
|
#include "SelectItem.h"
#include "LogicPlan.h"
#include "expr.h"
#include "TableRef.h"
namespace resolve
{
}
|
3731fdbb94cc93ad61bc57dbf642312bfe9e6e31
|
33980e68c638b4947ff74bfdd2373e0ed43a1c17
|
/src/BeeHandleSimple.hpp
|
60332d0c183d0a445a172a389d165ebfd50ab1f0
|
[] |
no_license
|
cdfritz7/OutlineDetectionAndSwarmDynamics
|
c95bf0aac816832ea1e897e697465311cd4893f9
|
02d1eb81c5f1ff4366254681995c8355704d629a
|
refs/heads/master
| 2020-07-23T00:14:24.106523
| 2020-05-02T21:26:15
| 2020-05-02T21:26:15
| 207,376,311
| 0
| 1
| null | 2020-04-19T15:54:01
| 2019-09-09T18:23:42
|
Python
|
UTF-8
|
C++
| false
| false
| 6,064
|
hpp
|
BeeHandleSimple.hpp
|
#include <iostream>
#include <vector>
#include <opencv.hpp>
#include <thread>
#include <math.h>
#define NUM_THREADS 8
// number of directions to average
#define DIR_MEMORY 10
using namespace std;
class BeeHandle
{
private:
int move_dist;
int max_x;
int max_y;
vector<cv::Point> bees;
vector<cv::Point> flowers;
thread threads [NUM_THREADS];
vector<vector<int>> past_dirs;
vector<int> dirs;
vector<int> landed;
int sound_divisor;
void join_threads() {
for(int i=0; i<NUM_THREADS; i++) {
threads[i].join();
}
}
void set_threads() {
for(int i=0; i<NUM_THREADS; i++) {
threads[i] = thread(&BeeHandle::move_bee, this, i);
}
}
// Map an increment ∈ {-1, 0, 1} in x and y direction to direction number ∈ [0,7]
// Assumes y increases as you move down the screen
int x_y_to_dir(int x, int y) {
if(x==-1) {
if(y==-1) {
return 7;
}
else if(y==0) {
return 6;
}
else {
return 5;
}
}
else if(x==0) {
if(y==-1) {
return 0;
}
// randomize direction if the bee didn't move
else if(y==0) {
return (rand() % 3)-1;
}
else {
return 4;
}
}
else {
if(y==-1) {
return 1;
}
else if(y==0) {
return 2;
}
else {
return 3;
}
}
}
void move_bee(int thread_num) {
int bee_per_thread = bees.size()/NUM_THREADS;
int start = bee_per_thread*thread_num;
int end = start + bee_per_thread;
for(int i=start; i<end; i++) {
bool did_land1 = false;
bool did_land2 = false;
int move_x = (rand() % 3)-1;
int move_y = (rand() % 3)-1;
int newX = (this->bees.at(i).x + move_x*move_dist)%max_x;
int newY = (this->bees.at(i).y + move_y*move_dist)%max_y;
if(newX < 0)
newX = max_x-1;
if(newY < 0)
newY = max_y-1;
cv::Point new_pos = cv::Point(newX, newY);
float currPotential = get_potential(this->bees.at(i),&did_land1);
float newPotential = get_potential(new_pos,&did_land2);
if(newPotential > currPotential){
bees.at(i) = new_pos;
int dir = x_y_to_dir(move_x, move_y);
// erase oldest direction
this->past_dirs.at(i).pop_back();
// insert new direction
auto it = this->past_dirs.at(i).begin();
this->past_dirs.at(i).insert(it, dir);
if(did_land2 && i%sound_divisor == 0){
landed.at(i/sound_divisor) = landed.at(i/sound_divisor)+1;
}
else if(!did_land2 && i%sound_divisor == 0){
landed.at(i/sound_divisor) = 0;
}
}
else {
if(did_land1 && i%sound_divisor == 0) {
landed.at(i/sound_divisor) = landed.at(i/sound_divisor)+1;
}
else if(!did_land1 && i%sound_divisor == 0) {
landed.at(i/sound_divisor) = 0;
}
}
}
}
public:
BeeHandle(){
max_x = 320;
max_y = 240;
}
BeeHandle(int maxX, int maxY, int sound_div){
max_x = maxX;
max_y = maxY;
sound_divisor = sound_div;
}
void add_bees(vector<cv::Point> locations){
for(unsigned i = 0; i < locations.size(); i++){
this->bees.push_back(locations.at(i));
// randomize current direction
int dir = (int)(rand()%8);
this->dirs.push_back(dir);
// initialize direction memory with random directions
vector<int> bee_past_dirs;
for(int j=0; j<DIR_MEMORY; j++) {
int dir = (int)(rand()%8);
bee_past_dirs.push_back(dir);
}
this->past_dirs.push_back(bee_past_dirs);
}
}
void add_bees(int num_bees){
landed.resize(num_bees/sound_divisor);
std::fill(landed.begin(), landed.end(), 0);
for(int i = 0; i < num_bees; i++){
cv::Point p1 = cv::Point((int)(rand()%max_x), (int)(rand()%max_y));
this->bees.push_back(p1);
// randomize current direction
int dir = (int)(rand()%8);
this->dirs.push_back(dir);
// initialize direction memory with random directions
vector<int> bee_past_dirs;
for(int j=0; j<DIR_MEMORY; j++) {
int dir = (int)(rand()%8);
bee_past_dirs.push_back(dir);
}
this->past_dirs.push_back(bee_past_dirs);
}
}
void add_flowers(vector<cv::Point> locations){
flowers = locations;
}
vector<cv::Point> get_bees(){
return this->bees;
}
vector<int> get_landed(){
return this->landed;
}
// Compute distance as the average of the last DIR_MEMORY directions
vector<int> get_dirs() {
for(int i=0; i<(int)past_dirs.size(); i++) {
int sum = 0.0;
for(int j=0; j<(int)past_dirs.at(0).size(); j++) {
sum += past_dirs.at(i).at(j);
}
dirs.at(i) = round(sum/DIR_MEMORY);
}
return dirs;
}
void clear_flowers(){
this->flowers.clear();
}
void clear_bees(){
this->bees.clear();
this->dirs.clear();
this->past_dirs.clear();
}
int distance(cv::Point p1, cv::Point p2){
return (int)cv::norm(p1-p2);
}
float get_potential(cv::Point p, bool *did_land){
float cur_potential = 0;
int resistance_str = 2000;
int attraction_str = 10000;
int bee_stride = 10;
int flower_stride = 1;
int random_off_bee = rand()%bee_stride;
int random_off_flower = rand()%flower_stride;
for(unsigned i = random_off_bee; i < bees.size(); i+=bee_stride){
int dist = distance(bees.at(i), p);
if(dist != 0)
cur_potential -= (float)resistance_str*bee_stride/(dist);
else
cur_potential -= resistance_str*bee_stride;
}
for(unsigned i = random_off_flower; i < flowers.size(); i+=flower_stride){
int dist = distance(flowers.at(i), p);
if(dist == 0){
*did_land = true;
}
if(dist != 0)
cur_potential += (float)attraction_str*flower_stride/dist;
else
cur_potential += attraction_str*attraction_str;
}
return cur_potential;
}
void update_movement(int moveDist){
move_dist = moveDist;
set_threads();
join_threads();
}
};
|
ac1a00784957338ef0947f031e4d51c876843bcd
|
9362d0cf299e3f196c05586028988ebcd906407e
|
/src/Relation.cpp
|
17d34c621b14f306dee6bf8078f93ff4b55feed1
|
[] |
no_license
|
parisbre56/devel_part_1
|
91d92e88765755b5407c1706daa9e6e3675ae010
|
5efaff53985118c6cab432e7838caa62b52e191d
|
refs/heads/master
| 2020-04-02T05:12:46.180716
| 2019-01-20T20:10:56
| 2019-01-20T20:10:56
| 154,058,311
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 8,575
|
cpp
|
Relation.cpp
|
/*
* Relation.cpp
*
* Created on: 21 ��ô 2018
* Author: parisbre56
*/
#include "Relation.h"
#include <cstring>
#include <sstream>
#include <stdexcept>
using namespace std;
Relation::Relation(uint64_t arraySize,
uint32_t sizeTableRows,
size_t sizePayloads,
bool* usedRows) :
numTuples(0),
highWaterMark(0),
arraySize(arraySize),
tuples(new Tuple*[arraySize]),
usedRows(
usedRows == nullptr ? new bool[sizeTableRows] { /*init to false*/} :
usedRows),
manageUsedRows(usedRows == nullptr),
sizeTableRows(sizeTableRows),
sizePayloads(sizePayloads) {
}
Relation::Relation(uint64_t arraySize,
uint32_t sizeTableRows,
size_t sizePayloads,
uint64_t numTuples,
bool* usedRows) :
numTuples(numTuples),
highWaterMark(numTuples),
arraySize(arraySize),
tuples(new Tuple*[arraySize] {/* init to nullptr */}),
usedRows(
usedRows == nullptr ? new bool[sizeTableRows] { /*init to false*/} :
usedRows),
manageUsedRows(usedRows == nullptr),
sizeTableRows(sizeTableRows),
sizePayloads(sizePayloads) {
}
Relation::Relation(const Relation& toCopy) :
numTuples(toCopy.numTuples),
highWaterMark(toCopy.numTuples),
arraySize(toCopy.arraySize),
tuples(new Tuple*[toCopy.arraySize]),
usedRows(new bool[toCopy.sizeTableRows]),
manageUsedRows(true),
sizeTableRows(toCopy.sizeTableRows),
sizePayloads(toCopy.sizePayloads) {
memcpy(usedRows, toCopy.usedRows, toCopy.sizeTableRows * sizeof(bool));
for (uint64_t i = 0; i < toCopy.numTuples; ++i) {
tuples[i] = new Tuple(*(toCopy.tuples[i]));
}
}
Relation::Relation(const Relation& toCopy, bool * const usedRows) :
numTuples(toCopy.numTuples),
highWaterMark(toCopy.numTuples),
arraySize(toCopy.arraySize),
tuples(new Tuple*[toCopy.arraySize]),
usedRows(usedRows),
manageUsedRows(false),
sizeTableRows(toCopy.sizeTableRows),
sizePayloads(toCopy.sizePayloads) {
for (uint64_t i = 0; i < toCopy.numTuples; ++i) {
tuples[i] = new Tuple(*(toCopy.tuples[i]));
}
}
Relation::Relation(Relation&& toMove) :
numTuples(toMove.numTuples),
highWaterMark(toMove.highWaterMark),
arraySize(toMove.arraySize),
tuples(toMove.tuples),
usedRows(toMove.usedRows),
manageUsedRows(toMove.manageUsedRows),
sizeTableRows(toMove.sizeTableRows),
sizePayloads(toMove.sizePayloads) {
toMove.tuples = nullptr;
toMove.usedRows = nullptr;
}
Relation::~Relation() {
//Delete all copies if this hasn't been moved
if (tuples != nullptr) {
for (uint64_t i = 0; i < highWaterMark; ++i) {
if (tuples[i] != nullptr) {
delete tuples[i];
}
}
delete[] tuples;
}
if (manageUsedRows && usedRows != nullptr) {
delete[] usedRows;
}
}
ResultContainer Relation::operator*(const Relation& cartesianProduct) const {
ResultContainer retResult(numTuples * cartesianProduct.numTuples,
sizeTableRows,
0);
for (uint32_t i = 0; i < sizeTableRows; ++i) {
if (usedRows[i] || cartesianProduct.usedRows[i]) {
retResult.setUsedRow(i);
}
}
for (uint64_t i = 0; i < numTuples; ++i) {
for (uint64_t j = 0; j < cartesianProduct.numTuples; ++j) {
Tuple toAdd(*(tuples[i]),
usedRows,
*(cartesianProduct.tuples[j]),
cartesianProduct.usedRows);
retResult.addTuple(move(toAdd));
}
}
return retResult;
}
uint64_t Relation::getNumTuples() const {
return numTuples;
}
uint64_t Relation::getArraySize() const {
return arraySize;
}
const bool* Relation::getUsedRows() const {
return usedRows;
}
bool Relation::getUsedRow(uint32_t row) const {
if (row >= sizeTableRows) {
throw runtime_error("Relation::getUsedRow: index out of bounds [row="
+ to_string(row)
+ ", sizeTableRows="
+ to_string(sizeTableRows)
+ "]");
}
return usedRows[row];
}
void Relation::setUsedRow(uint32_t row) {
if (row >= sizeTableRows) {
throw runtime_error("Relation::setUsedRow: index out of bounds [row="
+ to_string(row)
+ ", sizeTableRows="
+ to_string(sizeTableRows)
+ "]");
}
if (!manageUsedRows) {
throw runtime_error("Relation::setUsedRow: manageUsedRows is false");
}
usedRows[row] = true;
}
uint32_t Relation::getSizeTableRows() const {
return sizeTableRows;
}
size_t Relation::getSizePayloads() const {
return sizePayloads;
}
/** Add a copy of the Tuple to the array of tuples,
* incrementing the size of the underlying array
* automatically if necessary.
*
* The Relation will delete the created Tuple when it
* is deleted. **/
void Relation::addTuple(Tuple& tuple) {
if (numTuples >= arraySize) {
throw runtime_error("Relation::addTuple: reached limit, can't add more tuples [numTuples="
+ to_string(numTuples)
+ ", arraySize="
+ to_string(arraySize)
+ "]");
}
if (numTuples < highWaterMark) {
*(tuples[numTuples++]) = tuple;
}
else {
tuples[numTuples++] = new Tuple(tuple);
highWaterMark = numTuples;
}
}
void Relation::addTuple(Tuple&& tuple) {
if (numTuples >= arraySize) {
throw runtime_error("Relation::addTuple: reached limit, can't add more tuples [numTuples="
+ to_string(numTuples)
+ ", arraySize="
+ to_string(arraySize)
+ "]");
}
if (numTuples < highWaterMark) {
*(tuples[numTuples++]) = move(tuple);
}
else {
tuples[numTuples++] = new Tuple(move(tuple));
highWaterMark = numTuples;
}
}
/** Set the tuple at the given index. Use very carefully.
* Use only for loading table using multiple threads.
* It assumes you know what you're doing so it doesn't
* check if it's within bounds or if it hasn't been
* previously set. **/
void Relation::setTuple(uint64_t index, Tuple& tuple) {
tuples[index] = new Tuple(tuple);
}
void Relation::setTuple(uint64_t index, Tuple&& tuple) {
tuples[index] = new Tuple(move(tuple));
}
/** Get the tuple at the given index. **/
const Tuple* const * const Relation::getTuples() const {
return tuples;
}
const Tuple& Relation::getTuple(uint64_t index) const {
return *(tuples[index]);
}
void Relation::reset() { //TODO can be made more efficient by reusing tuples
numTuples = 0;
}
/*numTuples(toCopy.numTuples),
arraySize(toCopy.arraySize),
tuples(new Tuple*[toCopy.arraySize]),
usedRows(new bool[toCopy.sizeTableRows]),
manageUsedRows(true),
sizeTableRows(toCopy.sizeTableRows),
sizePayloads(toCopy.sizePayloads)*/
std::ostream& operator<<(std::ostream& os, const Relation& toPrint) {
os << "[Relation array_size="
<< toPrint.arraySize
<< ", numTuples="
<< toPrint.numTuples
<< ", highWaterMark="
<< toPrint.highWaterMark
<< ", sizeTableRows="
<< toPrint.sizeTableRows
<< ", sizePayloads="
<< toPrint.sizePayloads
<< ", manageUsedRows="
<< toPrint.manageUsedRows
<< ", usedRows=";
if (toPrint.usedRows == nullptr) {
os << "null";
}
else {
os << "[";
for (size_t i = 0; i < toPrint.sizeTableRows; ++i) {
if (i != 0) {
os << ", ";
}
os << toPrint.usedRows[i];
}
os << "]";
}
os << ", tuples=";
if (toPrint.tuples == nullptr) {
os << "null";
}
else {
os << "[";
for (uint64_t i = 0; i < toPrint.numTuples; ++i) {
os << "\n\t" << i << ": " << *(toPrint.tuples[i]);
}
os << "]";
}
os << "]";
return os;
}
|
93078c1f42550e6b26c23a28d26caa4dda9d91e0
|
979646a5c119cdc775cb048c1d288310d165db51
|
/338_Counting_Bits.cpp
|
40606d72ecbd09583147356bd36fc5e2b02adb65
|
[] |
no_license
|
liuminghao0830/leetcode
|
72a5a0a9539eb1f6b4f4446eaba97a8c94294abe
|
0d58a2f5a3062617e233674dd08f2e8e13fa327d
|
refs/heads/master
| 2021-06-22T16:33:25.636444
| 2021-02-15T07:23:36
| 2021-02-15T07:23:36
| 192,244,101
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 641
|
cpp
|
338_Counting_Bits.cpp
|
#include<bits/stdc++.h>
using namespace std;
/*
Given a non negative integer number num. For every numbers i
in the range 0 ≤ i ≤ num calculate the number of 1's in their
binary representation and return them as an array.
*/
class Solution {
public:
vector<int> countBits(int num) {
vector<int> dp(num + 1, 0);
for (int i = 1; i <= num; ++i){
if (i % 2 == 0) dp[i] = dp[i / 2];
else dp[i] = dp[i / 2] + 1;
}
return dp;
}
}; Solution solution;
int main(){
vector<int> res = solution.countBits(5);
for (int n : res) cout << n << " ";
cout << "\n";
return 0;
}
|
ebbb983cb8fba02d11c0aa2ccfabdca2c5c685b6
|
492976adfdf031252c85de91a185bfd625738a0c
|
/src/KingSystem/GameData/gdtSpecialFlags.cpp
|
0ecc96bf57654232a248a3d146e85d059b73eb82
|
[] |
no_license
|
zeldaret/botw
|
50ccb72c6d3969c0b067168f6f9124665a7f7590
|
fd527f92164b8efdb746cffcf23c4f033fbffa76
|
refs/heads/master
| 2023-07-21T13:12:24.107437
| 2023-07-01T20:29:40
| 2023-07-01T20:29:40
| 288,736,599
| 1,350
| 117
| null | 2023-09-03T14:45:38
| 2020-08-19T13:16:30
|
C++
|
UTF-8
|
C++
| false
| false
| 7,185
|
cpp
|
gdtSpecialFlags.cpp
|
#include "KingSystem/GameData/gdtSpecialFlags.h"
#include <prim/seadStringUtil.h>
#include "KingSystem/GameData/gdtCommonFlagsUtils.h"
#include "KingSystem/GameData/gdtFlagUtils.h"
namespace ksys::gdt {
const char* str_Dungeon = "Dungeon";
const char* str_Remains = "Remains";
const char* sSmallKeyNumFlagSuffix = "_SmallKeyNum";
const char* sDungeonClearFlagPrefix = "Clear_";
const char* sDungeonEnterFlagPrefix = "Enter_";
#define GDT_DEFINE_BOOL_GETTER(FLAG) \
bool getBool_##FLAG(bool debug = false) { return getBool(flag_##FLAG(), debug); }
GDT_DEFINE_BOOL_GETTER(SaveProhibition)
GDT_DEFINE_BOOL_GETTER(SaveProhibitionArea)
GDT_DEFINE_BOOL_GETTER(WarpProhibition)
GDT_DEFINE_BOOL_GETTER(WarpProhibitionArea)
GDT_DEFINE_BOOL_GETTER(WarpProhibitionArea_Fire_Relic)
GDT_DEFINE_BOOL_GETTER(KillTimeProhibition)
GDT_DEFINE_BOOL_GETTER(KillTimeProhibitionArea)
GDT_DEFINE_BOOL_GETTER(KillTimeProhibitionArea_Fire_Relic)
#undef GDT_DEFINE_BOOL_GETTER
s32 getSmallKeyFlag(s32 idx, bool debug = false) {
return getS32(flag_SmallKey(), idx, debug);
}
bool isSaveProhibited() {
if (getBool_SaveProhibition())
return true;
if (getBool_SaveProhibitionArea())
return true;
return false;
}
bool isWarpProhibited() {
if (getBool_WarpProhibition())
return true;
if (getBool_WarpProhibitionArea())
return true;
if (getBool_WarpProhibitionArea_Fire_Relic())
return true;
return false;
}
bool isKillTimeProhibited() {
if (getBool_KillTimeProhibition())
return true;
if (getBool_KillTimeProhibitionArea())
return true;
if (getBool_KillTimeProhibitionArea_Fire_Relic())
return true;
return false;
}
s32 getSmallKeyNum(const sead::SafeString& map, bool debug) {
if (map.startsWith(str_Remains)) {
sead::FixedSafeString<32> flag{map};
flag.append(sSmallKeyNumFlagSuffix);
return getS32ByKey(flag, debug);
}
const s32 dungeon_num = getDungeonNum(map);
if (dungeon_num == -1)
return 0;
return getSmallKeyFlag(dungeon_num, debug);
}
s32 getS32ByKey(const sead::SafeString& flag, bool debug) {
s32 value{};
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getS32(&value, flag);
else
mgr->getParam().get().getS32(&value, flag);
}
return value;
}
s32 getDungeonNum(const sead::SafeString& map) {
if (map.startsWith(str_Dungeon)) {
const sead::FixedSafeString<32> buffer{str_Dungeon};
s32 ret = -1;
const auto part = map.getPart(buffer.calcLength());
if (sead::StringUtil::tryParseS32(&ret, part, sead::StringUtil::CardinalNumber::Base10))
return ret;
}
return -1;
}
void incrementSmallKeyNum(const sead::SafeString& map, s32 value, bool debug) {
if (map.startsWith(str_Remains)) {
sead::FixedSafeString<32> flag{map};
flag.append(sSmallKeyNumFlagSuffix);
increaseS32CommonFlag(value, flag, -1, debug);
} else {
const s32 dungeon_number = getDungeonNum(map);
if (dungeon_number != -1)
increaseS32CommonFlag(value, "SmallKey", dungeon_number, debug);
}
}
bool setS32ByKey(s32 value, const sead::SafeString& flag, bool debug) {
auto* mgr = Manager::instance();
return mgr && mgr->setS32Special(value, flag, debug, true);
}
bool setBoolByKey(bool value, const sead::SafeString& flag, bool debug) {
auto* mgr = Manager::instance();
return mgr && mgr->setBoolSpecial(value, flag, debug, true);
}
bool getBoolByKey(const sead::SafeString& flag, bool debug) {
bool value{};
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getBool(&value, flag);
else
mgr->getParam().get().getBool(&value, flag);
}
return value;
}
bool isDungeonCleared(const sead::SafeString& map, bool debug) {
sead::FixedSafeString<32> flag{sDungeonClearFlagPrefix};
flag.append(map, 32 - sizeof("Clear_"));
return getBoolByKey(flag, debug);
}
void setDungeonCleared(const sead::SafeString& map, bool cleared, bool debug) {
sead::FixedSafeString<32> flag{sDungeonClearFlagPrefix};
flag.append(map, 32 - sizeof("Clear_"));
setBoolByKey(cleared, flag, debug);
}
bool isDungeonEntered(const sead::SafeString& map, bool debug) {
sead::FixedSafeString<32> flag{sDungeonEnterFlagPrefix};
flag.append(map, 32 - sizeof("Enter_"));
return getBoolByKey(flag, debug);
}
void setDungeonEntered(const sead::SafeString& map, bool cleared, bool debug) {
sead::FixedSafeString<32> flag{sDungeonEnterFlagPrefix};
flag.append(map, 32 - sizeof("Enter_"));
setBoolByKey(cleared, flag, debug);
}
f32 getF32ByKey(const sead::SafeString& flag, bool debug) {
f32 value{};
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getF32(&value, flag);
else
mgr->getParam().get().getF32(&value, flag);
}
return value;
}
void getStr64ByKey(const char** value, const sead::SafeString& flag, bool debug) {
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getStr64(value, flag);
else
mgr->getParam().get().getStr64(value, flag);
}
}
void getVec3fByKey(sead::Vector3f* value, const sead::SafeString& flag, bool debug) {
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getVec3f(value, flag);
else
mgr->getParam().get().getVec3f(value, flag);
}
}
s32 getS32ByKey(const sead::SafeString& flag, s32 sub_idx, bool debug) {
s32 value{};
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getS32(&value, flag, sub_idx);
else
mgr->getParam().get().getS32(&value, flag, sub_idx);
}
return value;
}
f32 getF32ByKey(const sead::SafeString& flag, s32 sub_idx, bool debug) {
f32 value{};
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getF32(&value, flag, sub_idx);
else
mgr->getParam().get().getF32(&value, flag, sub_idx);
}
return value;
}
void getStr64ByKey(const char** value, const sead::SafeString& flag, s32 sub_idx, bool debug) {
auto* mgr = Manager::instance();
if (mgr) {
if (debug)
mgr->getParamBypassPerm().get().getStr64(value, flag, sub_idx);
else
mgr->getParam().get().getStr64(value, flag, sub_idx);
}
}
bool setF32ByKey(f32 value, const sead::SafeString& flag, bool debug) {
auto* mgr = Manager::instance();
return mgr && mgr->setF32Special(value, flag, debug, true);
}
bool setStr64ByKey(const sead::SafeString& value, const sead::SafeString& flag, bool debug) {
auto* mgr = Manager::instance();
return mgr && mgr->setStr64Special(value, flag, debug, true);
}
} // namespace ksys::gdt
|
a3591671a0aac722dc7f363b21a735589f1e422a
|
2745f82d157f71c9fab6e6fd4f82699654c84f0f
|
/src/include/ext/station.cpp
|
3c7d958f7edd75af110f21d9f933cf42ea1bc079
|
[
"MIT"
] |
permissive
|
smorey2/libcu
|
cbfc10bdaab38f0caff04436adbf133601d8f746
|
b5deba3e9d011c550745ed9506e08ef1b8c8750c
|
refs/heads/master
| 2020-03-27T22:48:46.138258
| 2020-02-10T00:10:29
| 2020-02-10T00:10:29
| 147,263,110
| 0
| 0
| null | 2018-09-03T23:28:41
| 2018-09-03T23:28:41
| null |
UTF-8
|
C++
| false
| false
| 1,749
|
cpp
|
station.cpp
|
#if __OS_WIN
#include <windows.h>
#elif __OS_UNIX
#include <stdlib.h>
#include <string.h>
#endif
#include <stdio.h>
#include <assert.h>
#include <cuda_runtimecu.h>
#include <ext/station.h>
void stationCommand::dump() {
register unsigned char *b = (unsigned char *)&data;
register int l = length;
printf("Cmd: %d[%d]'", 0, l); for (int i = 0; i < l; i++) printf("%02x", b[i] & 0xff); printf("'\n");
}
static stationContext _ctx;
static bool _stationDevice = false;
static int *_deviceMap[STATION_DEVICEMAPS];
void stationHostInitialize() {
// create device maps
_stationDevice = true;
stationMap *d_deviceMap[STATION_DEVICEMAPS];
for (int i = 0; i < STATION_DEVICEMAPS; i++) {
cudaErrorCheckF(cudaHostAlloc((void **)&_deviceMap[i], sizeof(stationMap), cudaHostAllocPortable | cudaHostAllocMapped), goto initialize_error);
d_deviceMap[i] = _ctx.deviceMap[i] = (stationMap *)_deviceMap[i];
cudaErrorCheckF(cudaHostGetDevicePointer((void **)&d_deviceMap[i], _ctx.deviceMap[i], 0), goto initialize_error);
#ifndef _WIN64
_ctx.deviceMap[i]->offset = (intptr_t)((char *)_deviceMap[i] - (char *)d_deviceMap[i]);
//printf("chk: %x %x [%x]\n", (char *)_deviceMap[i], (char *)d_deviceMap[i], _ctx.deviceMap[i]->Offset);
#else
_ctx.deviceMap[i]->offset = 0;
#endif
}
cudaErrorCheckF(cudaMemcpyToSymbol(_stationDeviceMap, &d_deviceMap, sizeof(d_deviceMap)), goto initialize_error);
return;
initialize_error:
perror("stationHostInitialize:Error");
stationHostInitialize();
exit(1);
}
void stationHostShutdown() {
// close device maps
for (int i = 0; i < STATION_DEVICEMAPS; i++) {
if (_deviceMap[i]) { cudaErrorCheckA(cudaFreeHost(_deviceMap[i])); _deviceMap[i] = nullptr; }
}
}
|
818274c1a8ced007e5969437fc62607fef4058f9
|
515c4872cb974fa0e806368f75c5041bed6b4f0a
|
/Clases/Render.h
|
1176885beecf10153a7d411ab00d3a4bb5d81712
|
[] |
no_license
|
AlexRex/FV2015
|
2975f595b5a764471c154af19688fa5f02daf72c
|
fd67c0ee3be9ced5a32ee0e16385eb04883f2e6d
|
refs/heads/master
| 2021-01-13T02:37:46.516724
| 2015-05-20T21:35:07
| 2015-05-20T21:35:07
| 33,857,682
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,170
|
h
|
Render.h
|
/*
* File: Render.h
* Author: aletormat
*
* Created on 17 de abril de 2015, 9:54
*/
#ifndef RENDER_H
#define RENDER_H
#include <SFML/Graphics.hpp>
#include "../Includes/AnimatedSprite.hpp"
#include "Camara.h"
#include "Hud.h"
#include <iostream>
class Render {
public:
Render();
Render(const Render& orig);
virtual ~Render();
void Draw(sf::RenderWindow &window, const sf::Vector2f &lastPos, const sf::Vector2f &pos, float interpolacion, AnimatedSprite& animatedSprite);
void SetTextura(sf::Texture &tex);
void recibirCamara(Camara* cam);
void recibirHud(Hud* hud);
Animation* getWalkingAnimation() const { return walkingAnimation; }
Animation* getJumpingAnimation() const { return jumpingAnimation; }
Animation* getFallingAnimation() const { return fallingAnimation; }
sf::Vector2f* getRenderPos() const { return renderPos; }
private:
Camara* camara;
Hud* hud;
sf::Vector2f* renderPos;
Animation* walkingAnimation;
Animation* jumpingAnimation;
Animation* fallingAnimation;
};
#endif /* RENDER_H */
|
0d490badb7bb7b5abc3ad6eac516a558fbec1b14
|
d112993968aa5f26d94e94b1d949f8d54ca2b435
|
/sudoku.cpp
|
590e2cfd4f06925c3434bfb351f797391debabb0
|
[] |
no_license
|
igel-kun/sudoku
|
6d4783af629c8675479db8bd9a5dbc0492fd5093
|
47e19f660e748b85ba6e877817733f67bb2b119f
|
refs/heads/master
| 2021-01-25T07:08:23.910757
| 2014-11-06T12:52:06
| 2014-11-06T12:52:06
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 10,046
|
cpp
|
sudoku.cpp
|
/*****************************************
* general header file for sudoku puzzles
* and rules wrapper
* by M.Weller
****************************************/
#ifndef sudoku_cpp
#define sudoku_cpp
#include "sudoku.h"
void sudoku_cell::init(const uint _num_digits, const uint _x, const uint _y, const uint _content){
x = _x;
y = _y;
num_digits = _num_digits;
content = _content;
}
// constructor
sudoku_cell::sudoku_cell(const uint _num_digits, const uint _x, const uint _y, const uint _content){
init(_num_digits, _x, _y, _content);
}
// copy constructor
sudoku_cell::sudoku_cell(const sudoku_cell& cell){
init(cell.num_digits, cell.x, cell.y, cell.content);
}
// destructor
sudoku_cell::~sudoku_cell(){
}
// user interface
uint sudoku_cell::get_content() const{
return content;
}
void sudoku_cell::set_content(const uint _content){
content = _content;
}
void sudoku_cell::remove_content(){
set_content(0);
}
uint sudoku_cell::get_num_digits()const{
return num_digits;
}
uint sudoku_cell::get_x() const{
return x;
}
uint sudoku_cell::get_y() const{
return y;
}
uint sudoku::get_index(const uint x, const uint y) const{
return y * num_digits + x;
}
void sudoku::init(const uint digits, const vector<sudoku_cell*>* copy_grid){
num_digits = digits;
grid = new vector<sudoku_cell*>(num_digits * num_digits);
for(uint i = 0; i < digits; i++)
for(uint j = 0; j < digits; j++)
if(copy_grid)
(*grid)[get_index(i,j)] = new sudoku_cell(*((*copy_grid)[get_index(i,j)]));
else
(*grid)[get_index(i,j)] = new sudoku_cell(digits, i, j, 0);
}
char* sudoku::read_first_line(const char* filename){
FILE* f;
bool is_file = false;
dbgout << "trying to open \"" << filename << "\"" << endl;
if(!strcmp(filename,"stdin")) f = stdin; else {
f = fopen(filename, "ro");
is_file = true;
if(!f) diewith("error opening \"" << filename << "\"" << endl);
}
char* s = (char*)malloc(MAX_DIGITS + 1);
if(!fscanf(f, "%s", s)) diewith("error reading \"" << filename << "\": bad format" << endl);
if(is_file) fclose(f);
return s;
}
void sudoku::mem_free(){
for(uint i = 0; i < num_digits * num_digits; i++)
delete (*grid)[i];
delete grid;
}
// constructor
sudoku::sudoku(const uint digits){
init(digits);
}
// construct from a file
sudoku::sudoku(const char* filename, const bool read_field){
char* s = read_first_line(filename);
init(strlen(s));
dbgout << "number of digits: " << num_digits << endl;
if(read_field) read_from_file(filename, strcmp(filename,"stdin")?NULL:s);
free(s);
}
// copy constructor
sudoku::sudoku(const sudoku& s){
init(s.num_digits, s.grid);
}
// destructor
sudoku::~sudoku(){
mem_free();
}
// write a cell to a position in the grid
bool sudoku::put_cell(const uint x, const uint y, sudoku_cell* cell){
if((x < num_digits) && (y < num_digits)){
delete (*grid)[y * num_digits + x];
(*grid)[y * num_digits + x] = cell;
} else return false;
return true;
}
// read a cell from a position in the grid
sudoku_cell* sudoku::get_cell(const uint x, const uint y) const{
if((x < num_digits) && (y < num_digits))
return (*grid)[y * num_digits +x];
else return NULL;
}
// return the squared order [ = how many different digits there are]
uint sudoku::getnum_digits() const{
return num_digits;
}
// return a set of cells in row y
void sudoku::getrow(const uint y, set<sudoku_cell*>* group) const{
for(uint i = 0; i < num_digits; i++)
group->insert((*grid)[get_index(i,y)]);
}
// return a set of cells in the column x
void sudoku::getcolumn(const uint x, set<sudoku_cell*>* group) const{
for(uint i = 0; i < num_digits; i++)
group->insert((*grid)[get_index(x,i)]);
}
// return a set of cells in the square n
void sudoku::getsquare(const uint n, set<sudoku_cell*>* group) const{
uint order = (uint)sqrt((double)num_digits);
uint sq_x = n % order;
uint sq_y = n / order;
for(uint i = 0; i < order; i++)
for(uint j = 0; j < order; j++)
group->insert((*grid)[get_index(order * sq_x + i, order * sq_y + j)]);
}
// get the n'th [row, col, square] (dependent on group_nr)
set<sudoku_cell*>* sudoku::getgroup(const uint n, const uint group_nr) const {
set<sudoku_cell*>* group = new set<sudoku_cell*>();
switch(group_nr){
case 0: getrow(n, group); break;
case 1: getcolumn(n, group); break;
case 2: getsquare(n, group); break;
}
return group;
}
// get the [row, col, square] (dependent on group_nr) of the cell at (x,y)
set<sudoku_cell*>* sudoku::getgroup(const uint x, const uint y, const uint group_nr) const {
set<sudoku_cell*>* group = new set<sudoku_cell*>();
switch(group_nr){
case 0: getrow(x,y, group); break;
case 1: getcolumn(x,y, group); break;
case 2: getsquare(x,y, group); break;
}
return group;
}
// return a set of cells in the same row as cell (x,y)
void sudoku::getrow(const uint x, const uint y, set<sudoku_cell*>* group) const{
getrow(y,group);
}
// return a set of cells in the same column as cell (x,y)
void sudoku::getcolumn(const uint x, const uint y, set<sudoku_cell*>* group) const{
getcolumn(x, group);
}
// return a set of cells in the same square as cell (x,y)
void sudoku::getsquare(const uint x, const uint y, set<sudoku_cell*>* group) const{
uint order = (uint)sqrt((double)num_digits);
uint sq_x = x / order;
uint sq_y = y / order;
getsquare(sq_y * order + sq_x, group);
}
// read a sudoku field from a given file with the first line provided in first
void sudoku::read_from_file(const char* filename, const char* first){
FILE* f;
bool is_file = false;
if(!strcmp(filename,"stdin")) f = stdin; else {
f = fopen(filename, "ro");
is_file = true;
}
dbgout << "reading sudoku data from \"" << filename << "\"" << endl;
if(!f) diewith("error opening \""<< filename <<"\"" << endl);
uint digits[num_digits][num_digits];
unsigned char* buffer = (unsigned char*)malloc(num_digits + 1); // insecure, may cause segfault
for(uint row = 0; row < num_digits; ++row){
if(first && !row){
strcpy((char*)buffer, first);
}else{
if(!fscanf(f, "%s", (char*)buffer))
diewith("error reading from \"" << filename << "\"" << endl);
}
dbgout << "read \"" << buffer << "\" from \"" << filename << "\"" << endl;
if(strlen((char*)buffer) < num_digits){
diewith("error reading \"" << filename << "\": not enough digits in row" << row << endl);
} else {
for(uint col = 0; col < num_digits; ++col){
if((buffer[col] < '0') || (buffer[col] > '0'+num_digits))
digits[col][row] = 0;
else digits[col][row] = buffer[col] - '0';
}
}
}
if(is_file) fclose(f);
free(buffer);
for(uint col = 0; col < num_digits; ++col)
for(uint row = 0; row < num_digits; ++row){
(*grid)[get_index(col, row)]->set_content(digits[col][row]);
}
}
// output the grid to the stardard output stream
void sudoku::print() const{
uint zeroes = 0;
for(uint j = 0; j < num_digits; j++){
for(uint i = 0; i < num_digits; i++){
cout << (char)('0' + get_cell(i,j)->get_content());
if(!get_cell(i,j)->get_content()) ++zeroes;
}
cout << endl;
}
cout << zeroes << " empty cells" << endl;
}
bool sudoku::is_valid() const{
set<sudoku_cell*>* group;
bool bitfield[num_digits];
bool result = true;
for(uint group_nr = 0; group_nr < 3; group_nr++){
for(uint i = 0; i < num_digits; i++){
group = getgroup(i, group_nr);
for(uint i = 0; i < num_digits; i++)
bitfield[i] = false;
for(set<sudoku_cell*>::iterator j = group->begin(); j != group->end(); j++)
bitfield[(*j)->get_content() - 1] = true;
delete group;
for(uint i = 0; i < num_digits; i++)
if(!bitfield[i]) return false;
}
}
return result;
}
// equality on several levels [see above]
bool sudoku::is_equal(const sudoku& s, const uint levels) const{
// check for permuted digits
//EQ_PERMUTE_DIGITS
uint x,y;
bool result = false;
if(!result && (levels & EQ_PERMUTE_DIGITS)){
uint *perm = new uint[num_digits];
uint content;
for(uint i = 0; i < num_digits; i++) perm[i] = 0;
x=y=0; result = true;
while((y < num_digits) && result){
content = s.get_cell(x,y)->get_content();
if(content){
content--;
if(perm[content] == 0)
perm[content] = get_cell(x,y)->get_content();
else
if(perm[content] != get_cell(x,y)->get_content()) result = false;
} else
if(get_cell(x,y)->get_content()) result = false;
x++;
if(x == num_digits) { x=0; y++;}
}
delete perm;
}
//EQ_ROTATE
if(!result && (levels & EQ_ROTATE)){
for(uint i = 1; i < 4; i++){
}
}
//EQ_FLIP
if(!result && (levels & EQ_FLIP)){
}
//EQ_TRANSPOSE
if(!result && (levels & EQ_TRANSPOSE)){
x=y=0; result = true;
while((y < num_digits) && result){
if(s.get_cell(x,y)->get_content() != get_cell(y,x)->get_content()) result = false;
x++;
if(x == num_digits) { x=0; y++;}
}
}
#warning continue here!
return result;
}
bool sudoku::operator==(const sudoku& s) const{
return is_equal(s, 0);
}
ostream& operator<<(ostream& os, const sudoku& s){
for(uint i = 0; i < s.num_digits; i++){
for(uint j = 0; j < s.num_digits; j++)
os << (*s.grid)[s.get_index(i, j)]->get_content();
os << "\n";
}
return os;
}
istream& operator>>(istream& is, sudoku& s){
uint* digits = NULL;
char* str = (char*)malloc(MAX_DIGITS + 1); // insecure, may cause segfault
uint num_digits = 1;
for(uint y = 0; y < num_digits; y++){
is >> str;
dbgout << "read " << str << " from the stream" << endl;
if(!y) {
num_digits = strlen(str);
dbgout << "getting " << sizeof(uint) * num_digits * num_digits << " bytes for digits"<<endl;
digits = (uint*)malloc(sizeof(uint) * num_digits * num_digits);
}
if(strlen(str) < num_digits){
diewith("error reading stream: not enough digits in a row" << endl);
} else {
for(int x = 0; x < (int)num_digits; x++)
digits[s.get_index(x,y)] = str[x] - '0';
}
}
free(str);
s.mem_free();
s.init(num_digits);
for(uint x = 0; x < num_digits * num_digits; x++)
((*s.grid)[x])->set_content(digits[x]);
free(digits);
return is;
}
#endif
|
a5e6c61ae20c80381a086af9ee0bda8c931bc5d6
|
2572a2dc50392495be992c1f5b9225feac707dce
|
/CodeForces/Div2&3/80/A.cpp
|
deabdf4bac1db8b32be1d55b3ee1d5852d1b4927
|
[] |
no_license
|
agentmishra/DSA
|
f60aabb0c77f07a665944f224935103b29cedcf5
|
63cd024bafec0b25e150b51b88e4563e31a62ef9
|
refs/heads/master
| 2023-03-25T23:44:44.199513
| 2021-01-02T16:00:08
| 2021-01-02T16:00:08
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 571
|
cpp
|
A.cpp
|
#include <bits/stdc++.h>
#define ll long long
#define newline "\n";
#define loop(from,to) for(int i=from;i<to;i++)
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
using namespace std;
int main()
{
OJ;
int n;
cin >> n;
int reqd = n - 10;
int ans = 0;
if(reqd>0)
{
if(reqd == 1)
ans = 4;
else if(reqd <= 9)
ans = 4;
else if(reqd == 10)
ans = 15;
else if(reqd == 11)
ans = 4;
}
cout<<ans<<newline
return 0;
}
|
f8a46b996e7382956ef2388fc1f1bacd4ef12662
|
7092ff8d7cf0289e17da2ecc9c622fe21581addf
|
/sg_agent/src/remote/monitor/monitor_collector.h
|
32b4d23b50382fe7e226a410d0f42d8e2618929f
|
[
"Apache-2.0"
] |
permissive
|
fan2008shuai/octo-ns
|
e37eaf400d96e8a66dc894781574e2b5c275f43a
|
06827e97dc0a9c957e44520b69a042d3fb6954af
|
refs/heads/master
| 2020-05-27T19:40:42.233869
| 2019-06-09T15:09:48
| 2019-06-09T15:09:48
| 188,765,162
| 0
| 0
|
Apache-2.0
| 2019-05-27T03:30:23
| 2019-05-27T03:30:21
| null |
UTF-8
|
C++
| false
| false
| 2,152
|
h
|
monitor_collector.h
|
/**
* xxx is
* Copyright (C) 20xx THL A29 Limited, a xxx company. All rights reserved.
*
* Licensed under the xxx
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef OCTO_SRC_MONITOR_COLLECTOR_H
#define OCTO_SRC_MONITOR_COLLECTOR_H
#include <assert.h>
#include <string>
#include <map>
#include <list>
#include <iterator>
#include <stdio.h>
#include <evhttp.h>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <muduo/net/EventLoop.h>
#include <muduo/net/EventLoopThread.h>
#include <muduo/net/EventLoopThreadPool.h>
#include <boost/algorithm/string/trim.hpp>
#include "cJSON.h"
#include "config_loader.h"
#include "falcon_mgr.h"
#include "inc_comm.h"
namespace meituan_mns {
typedef struct cpu_util{
unsigned long total_cpu_delta;
unsigned long proc_cpu_delta;
cpu_util(){total_cpu_delta = 0.0;proc_cpu_delta = 0.0;};
}cpu_util_t;
class MonitorCollector {
private:
MonitorCollector() : has_init_(false),
end_point_(""),
agent_pid_(""),
monitor_data_(boost::unordered_map<std::string, int>()) {};
public:
~MonitorCollector() {};
static MonitorCollector *GetInstance();
int DoInitMonitorInfo();
int GetCollectorMonitorInfo(std::string &mInfo);
int CollectorInfo2Json(cJSON *json, cJSON *json_arrary, int type);
float CalcuProcCpuUtil(const int& pid);
private:
void SetValueByType(cJSON *root,int type);
void GetEndPoint(std::string &value);
int64_t GetTimeStamp();
static MonitorCollector *monitor_collector_;
static muduo::MutexLock monitor_collector_lock_;
std::map<int, std::string> metric_value_;
bool has_init_;
std::string end_point_;
std::string agent_pid_;
cpu_util_t cpu_jiff_value_;
boost::unordered_map<std::string, int> monitor_data_;
};
}
#endif //OCTO_SRC_MONITOR_COLLECTOR_H
|
a834dbfb9370e11341734e15506f3494d891d4fa
|
bef08bfd164a6783e38706c5faf9b3773472f81c
|
/unused/input.cpp
|
4cb83407dbf8eabe8e209d13cb5ead42d12546d8
|
[] |
no_license
|
s89162504/CSE231-LLVM_Program_Analysis
|
a8011f6557c287ae1e68577be1585923aa7d3eb1
|
98fcfb260c187bd126cd7167294fbc5646074de0
|
refs/heads/master
| 2021-06-13T12:52:59.253801
| 2017-03-28T21:42:37
| 2017-03-28T21:42:37
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 357
|
cpp
|
input.cpp
|
#include <iostream>
using namespace std;
//opt -load LLVMTestPass.so -TestPass < ./input.ll > /dev/null
int f(int a){
if(a < 3){
return 0;
}
return a + 5;
}
int main(){
int a = 3;
if (a == 3){
int d = 4;
a++;
if(a > 5){
a = a * d;
}
}
int b = 5;
cout << a * b << endl;
// cout << f(a) << endl;
return 0;
}
|
015f86520045562d6baf7947669a0d269c912fec
|
c6309c911ec4bb5a849caac75251dc26a5232372
|
/main.cpp
|
0b4993fc53121d66dcd2ab9540b5692fcbffe502
|
[] |
no_license
|
williamchoi7090/one-C--1
|
a4a43de1a37edc023a779f172dbb6075c32e2e98
|
dcea77142f50410218b4b1a79bce402b219c45ba
|
refs/heads/master
| 2023-03-31T10:33:02.785745
| 2021-04-05T04:07:32
| 2021-04-05T04:07:32
| 354,713,028
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,728
|
cpp
|
main.cpp
|
#include <bits/stdc++.h>
using namespace std;
int precedence(char cpp){
if(cpp == '+'||cpp == '-')
return 1;
if(cpp == '*'||cpp == '/')
return 2;
return 0;
}
int applycpp(int a, int b, char cpp){
switch(cpp){
case '+': return a + b;
case '-': return a - b;
case '*': return a * b;
case '/': return a / b;
}
}
int evaluate(string pp){
int n;
stack <int> up;
stack <char> down;
for(n = 0; n < pp.length(); n++){
if(pp[n] == ' ')
continue;
else if(pp[n] == '('){down.push(pp[n]);
}
else if(isdigit(pp[n])){
int val = 0;
while(n < pp.length() && isdigit(pp[n])){
val = (val*10) + (pp[n]-'0');
n++;
}
up.push(val);
n--;
}
else if(pp[n] == ')'){
while(!down.empty() && down.top() != '('){
int val2 = up.top();
up.pop();
int val1 = up.top();
up.pop();
char cpp = down.top();
down.pop();
up.push(applycpp(val1, val2, cpp));
}
if(!down.empty())
down.pop();
}
else{
while(!down.empty() && precedence(down.top())>= precedence(pp[n])){
int val2 = up.top();
up.pop();
int val1 = up.top();
up.pop();
char cpp = down.top();
down.pop();
up.push(applycpp(val1, val2, cpp));
}
down.push(pp[n]);
}
}
while(!down.empty()){
int val2 = up.top();
up.pop();
int val1 = up.top();
up.pop();
char cpp = down.top();
down.pop();
up.push(applycpp(val1, val2, cpp));
}
return up.top();
}
int main() {
cout << "25+5*2= " << evaluate("25+5*2") << "\n";
cout << "25*5+2= " << evaluate("25*5+2") << "\n";
cout << "25*(2+5)" << evaluate("25*(2+5)") << "\n";
cout << "25*(5+2)*2= " << evaluate("25*(5+2)*2");
return 0;
}
|
39d2abfaa814a6776c7415874a7cd30c59e6833a
|
86d1211fec5bd1c2259844aca1c6d2ef89c91045
|
/C-Compiler/cifa.cpp
|
5c44e3364a461398e2ef169629f1dfe572de1964
|
[] |
no_license
|
LokeZhou/Compiler_Loke
|
5d1a602b1f0813f7fe4609fb0d1e609c6d34bb7f
|
2d52fb2a8d82b9243ffcd698521b6d38aa71da9d
|
refs/heads/master
| 2021-01-12T06:30:49.824210
| 2016-12-26T09:10:01
| 2016-12-26T09:10:01
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 24,224
|
cpp
|
cifa.cpp
|
#include "cifa.h"
Token tok;
vector<Token> token;
char ch; //当前字符
string strToken;
string programme;
vector<string> keywords; //保留字表
vector<string> Id; //符号表code=0
vector<string> ConstNum; //常数表code=3
vector<string> ConstString; //字符串常量表code=2
vector<string> ConstChar; //字符常量表code=1
int file_pointer;
/**
Token串
*/
GCToken token_cifa[1000];
/**
Token串数组中的Token串数量
*/
int zongzishu;
/*char shuzi[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
char zimu[] = { '_', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k',
'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F',
'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' };
char bianbiefu[] = { '.', '\'', '"', ' ' };*/
char yunsuanfu[][4] = { "!", "&", "~", "^", "*", "/", "%", "+", "-", "<", ">", "=", "->", "++", "--", "<<",
">>", "<=", ">=", "==", "!=", "&&", "||", "+=", "-=", "*=", "/=", "^=", "&=", "~=", "%=", "|", "<<=", ">>=" }; // +61
char xianjiefu[][4] = { "(", ")", "[", "]", "{", "}", ".", "#", ",", ";", "'", "\"" }; //+100
char guanjianzi[][100] = { "auto", "break", "case", "char", "const", "continue", "default", "do",
"double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", "register",
"restrict", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union",
"unsigned", "void", "volatile", "while", "bool", "Complex", "Imaginary","cin","cout"}; //+1
void Psynbl()
{
cout << "Synbl List:\n";
for (int i = 0; i < SYNBL.size(); i++)
{
cout << "Name: ";
switch (SYNBL[i].name.code)
{
case 0:cout << Id[SYNBL[i].name.value] << "\t"; break;
case 1:cout << ConstChar[SYNBL[i].name.value] << "\t"; break;
case 2:cout << ConstString[SYNBL[i].name.value] << "\t"; break;
case 3:cout << ConstNum[SYNBL[i].name.value] << "\t"; break;
default:cout << keywords[SYNBL[i].name.code] << "\t";
}
cout << "TYPEL: " << TYPEL[SYNBL[i].type].name << "\t";
switch (SYNBL[i].cat)
{
case 1:cout << "FUNC\n"; break;
case 2:cout << "VARI\n"; break;
case 3:cout << "PARA\n"; break;
case 4:cout << "DOMA\n"; break;
default:cout << "ERRO\n"; break;
}
}
}
int InsertConstNum(string strToken){
ConstNum.push_back(strToken);
return ConstNum.size() - 1;
}
char zf; //字符
char dqdc[100];
char wenben[10000];
int wtp;//指向当前字符 替换wenbenxuhao
int zifushu;
void dcqk()
{
for (int i = 0; i<100; i++){ dqdc[i] = ' '; }
}
void dcqw()
{
for (int i = 0; i<100; i++)
{
if (dqdc[i] == ' ' || dqdc[i] == '\0'){ dqdc[--i] = '\0'; break; }
}
}
int duqu()
{
zifushu = 0;
FILE *fp = fopen("D:\\QT/Code/Compiler/C-Compiler/wenben.txt", "r");
if (fp == NULL){ printf("No File\n"); fclose(fp); return 0; }
else
{
while ((zf = fgetc(fp)) != EOF)
{
if (zf != '\n'&&zf != '\t'){ wenben[zifushu++] = zf; }
else { wenben[zifushu++] = ' '; }
}
}
printf("Reading Finished\n");
fclose(fp);
return 1;
}
int duAsm()
{
zifushu = 0;
FILE *fp = fopen("D:\\QT/Code/Compiler/C-Compiler/test.asm", "r");
if (fp == NULL){ printf("No File\n"); fclose(fp); return 0; }
else
{
while ((zf = fgetc(fp)) != EOF)
{
wenben[zifushu++] = zf;
}
}
printf("Reading Finished\n");
fclose(fp);
return 1;
}
int zfleixing(char w)
{
/* for (int bijiao = 0; bijiao<53; bijiao++)
{
if (zi == zimu[bijiao])return 0;
}
for (int bijiao = 0; bijiao<10; bijiao++)
{
if (zi == shuzi[bijiao])return 52;
}
for (int bijiao = 0; bijiao<4; bijiao++)
{
if (zi == bianbiefu[bijiao])return bijiao + 55;
}
return 1;*/
if((w>='a'&&w<='z')||(w>='A'&&w<='Z')||(w=='_'))return 0;//字母,包括下划线
else if(w>='0'&&w<='9')return 52;//数字
else if(w=='.') return 55;//以下为有特殊作用的符号,小数点区分整数和浮点数,单双引号区别字符常量字符串常量与自定义标识符
else if(w=='\'')return 56;
else if(w=='"')return 57;
else if(w==' ')return 58;
else return 1;
}
int fhleixing(char* dc)
{
for (int bijiao = 0; bijiao<34; bijiao++)
{
if (strcmp(dc, yunsuanfu[bijiao]) == 0)return bijiao + 61;
}
for (int bijiao = 0; bijiao<12; bijiao++)
{
if (strcmp(dc, xianjiefu[bijiao]) == 0)return bijiao + 100;
}
if (strlen(dc) == 1)return 994; //无符号
else return 0;
}
int quzi(){
//按一定词法规则划分完整的单词
dcqk();
int i = 0;
int biaoji = 999;
while (wenben[wtp] == ' ')wtp++;//从非空开始读
if (wtp<zifushu){
while (wenben[wtp] != ' ')
{
biaoji = zfleixing(wenben[wtp]);
dqdc[i++] = wenben[wtp++];
if (biaoji == 0)//首字母是字母或_,可能是标识符/变量名/保留字
{
while (zfleixing(wenben[wtp]) == 0 || zfleixing(wenben[wtp]) == 52)//字母或_或数字,符合标识符定义规则
{
dqdc[i++] = wenben[wtp++];
}
dqdc[i] = '\0'; return 0;
}
else if (biaoji == 56)//首字符是单引号 字符常量
{
dqdc[i++] = wenben[wtp++];
if (zfleixing(wenben[wtp]) == 56)
{
dqdc[i++] = wenben[wtp++];
dqdc[i] = '\0'; return 56;
}
else { dqdc[i] = '\0'; return 990; } //单字符错误
}
else if (biaoji == 57)//首字符是双引号 字符串常量
{
while (zfleixing(wenben[wtp]) != 57){ dqdc[i++] = wenben[wtp++]; }
dqdc[i++] = wenben[wtp++];
dqdc[i] = '\0'; return 57;
}
else if (biaoji == 52)
{
while (zfleixing(wenben[wtp]) == 52){ dqdc[i++] = wenben[wtp++]; }
if (zfleixing(wenben[wtp]) == 55){ dqdc[i++] = wenben[wtp++]; }//小数点
else { dqdc[i] = '\0'; return 51; }
if (zfleixing(wenben[wtp]) == 52){ dqdc[i++] = wenben[wtp++]; }
else { dqdc[i] = '\0'; return 991; } //数字错误
while (zfleixing(wenben[wtp]) == 52){ dqdc[i++] = wenben[wtp++]; }
if (wenben[wtp] == 'f'){ dqdc[i++] = wenben[wtp++]; dqdc[i] = '\0'; return 53; }
else if (wenben[wtp] == 'd'){ dqdc[i++] = wenben[wtp++]; dqdc[i] = '\0'; return 54; }
dqdc[i] = '\0'; return 53;
}
else if (biaoji == 1)
{
while (zfleixing(wenben[wtp]) == 1 && wenben[wtp] != ' ' && wtp < zifushu){ dqdc[i++] = wenben[wtp++]; }
dqdc[i] = '\0'; return 1;
}
else { dqdc[i] = '\0'; return biaoji; }
}
}
//下面的return肯定走不到,但是不写的话,编译器会报错,所以必须写。
return 1000;
}
void huaci()
{
int fuhaobiaoaddr = 0;
zongzishu = 0;
for (wtp = 0; wtp<zifushu;)
{
int leix = quzi();
if (leix == 1000)
{
wtp = zifushu;
}
else if (leix == 0)
{
int bijiao;
for (bijiao = 0; bijiao <= 38; bijiao++)
{
if (strcmp(dqdc, guanjianzi[bijiao]) == 0)//关键字表!!为什么不直接做成token序列!!!!
{
strcpy(token_cifa[zongzishu].content, dqdc);
strcpy(token_cifa[zongzishu].describe, "KEY_DESC\0");
token_cifa[zongzishu].type = bijiao + 1;
//keyMap.push_back(make_pair(token_cifa[zongzishu].content,token_cifa[zongzishu].type));
zongzishu++;
break;
}
}
if (bijiao == 39)//用户自定义标识符,放入符号表
{
strcpy(token_cifa[zongzishu].content, dqdc);
strcpy(token_cifa[zongzishu].describe, "IDENTIFER_DESC\0");
token_cifa[zongzishu].type = 40;
token_cifa[zongzishu].addr = fuhaobiaoaddr++;//!!
zongzishu++;
}
}
else if (leix == 56)//字符常量
{
strcpy(token_cifa[zongzishu].content, dqdc);
strcpy(token_cifa[zongzishu].describe, "ACHAR_DESC\0");
token_cifa[zongzishu].type = leix;
zongzishu++;
}
else if (leix == 57)//字符串常量
{
strcpy(token_cifa[zongzishu].content, dqdc);
strcpy(token_cifa[zongzishu].describe, "ASTRING_DESC\0");
token_cifa[zongzishu].type = leix;
zongzishu++;
}
else if (leix <= 54 && leix >= 51)//数字常量
{
strcpy(token_cifa[zongzishu].content, dqdc);
strcpy(token_cifa[zongzishu].describe, "CONSTANT_DESC\0");
token_cifa[zongzishu].type = leix;
zongzishu++;
}
else if (leix == 1)
{
for (;;)
{
int fhlx = fhleixing(dqdc);
if (fhlx == 0)
{
dcqw();
wtp--;
}
else if (fhlx == 994)//fhleixing返回值994 if (strlen(dc) == 1)return 994;
{
strcpy(token_cifa[zongzishu].content, dqdc);
strcpy(token_cifa[zongzishu].describe, "ERROR_OPE\0");
token_cifa[zongzishu].type = fhlx;
zongzishu++;
break;
}
else
{
strcpy(token_cifa[zongzishu].content, dqdc);
token_cifa[zongzishu].type = fhlx;
if (fhlx<99)//运算符
{
strcpy(token_cifa[zongzishu].describe, "OPE_DESC\0");
//operMap.push_back(make_pair(token_cifa[zongzishu].content,token_cifa[zongzishu].type));
}
else//边界符
{
strcpy(token_cifa[zongzishu].describe, "CLE_OPE_DESC\0");
//limitMap.push_back(make_pair(token_cifa[zongzishu].content,token_cifa[zongzishu].type));
}
zongzishu++;
break;
}
}
}
else
{
strcpy(token_cifa[zongzishu].content, dqdc);
if (leix == 990)
{
strcpy(token_cifa[zongzishu].describe, "ERROR_ACHAR\0");
token_cifa[zongzishu].type = leix;
}
else if (leix == 991)
{
strcpy(token_cifa[zongzishu].describe, "ERROR_CONSTANT\0");
token_cifa[zongzishu].type = leix;
}
zongzishu++;
}
}
}
void zfprint(int zfsh)
{
printf("<");
printf("%s", token_cifa[zfsh].content);
printf(">\t");
printf("<");
if (token_cifa[zfsh].type<9)printf("0");
if (token_cifa[zfsh].type<99)printf("0");
printf("%d", token_cifa[zfsh].type);
printf(">\t");
printf("<");
printf("%s", token_cifa[zfsh].describe);
printf(">\t");
if (token_cifa[zfsh].addr != 0)
{
printf("<");
if (token_cifa[zfsh].addr<9)printf("0");
if (token_cifa[zfsh].addr<99)printf("0");
printf("%d", token_cifa[zfsh].addr);
printf(">");
}
}
void shuchu()
{
printf("序号\tContent\tType\tDescribe\t\tAddr\n");
for (int wshu = 0; wshu<zongzishu; wshu++)
{
if (wshu<9)printf("0");
if (wshu<99)printf("0");
printf("%d", wshu + 1);
printf("\t");
zfprint(wshu);
printf("\n");
}
/*
for(int i=0;i<keyMap.size();i++)
{
printf("%s,%d\n",keyMap[i].first,keyMap[i].second);
}
for(int i=0;i<operMap.size();i++)
{
printf("%s,%d\n",operMap[i].first,operMap[i].second);
}
for(int i=0;i<limitMap.size();i++)
{
printf("%s,%d\n",limitMap[i].first,limitMap[i].second);
}
*/
}
void keyinit()
{
keywords.resize(38);
keywords[4] = "main";
keywords[5] = "while";
keywords[6] = "if";
keywords[7] = "char";
keywords[8] = "int";
keywords[9] = "float";
keywords[10] = "struct";
keywords[11] = "+";
keywords[12] = "-"; //提供给语法分析
keywords[13] = "*";
keywords[14] = "/"; //提供给语法分析
keywords[15] = "{";
keywords[16] = "}";
keywords[17] = "=";
keywords[18] = ",";
keywords[19] = "[";
keywords[20] = "]";
keywords[21] = ";";
keywords[22] = "\"";
keywords[23] = "\'";
keywords[24] = "(";
keywords[25] = ")";
keywords[26] = "&";
keywords[27] = "|";
keywords[28] = "!";
keywords[29] = "void";
keywords[30] = "else";
keywords[31] = "return";
keywords[32] = "&&";
keywords[33] ="||";
keywords[34] ="cout";
keywords[35] ="cin";
keywords[36] ="<<";
keywords[37] =">>";
}
void zhuanma()
{
Id.clear(); //符号表的序列项表
ConstNum.clear(); //常数表的表
ConstString.clear(); //字符串常量表
ConstChar.clear(); //字符常量表
for (int dangqiandanci = 0; dangqiandanci<zongzishu; dangqiandanci++)
{
switch (token_cifa[dangqiandanci].type)
{
case 40:
{
if (strcmp(token_cifa[dangqiandanci].content, "main") == 0)
{
tok.code = 4;
tok.value = 0;
token.push_back(tok);
}
else
{
int i;
for (i = 0; i < Id.size(); i++) //查找表中是否已经存在
{
if (!Id[i].compare(token_cifa[dangqiandanci].content))
break;
}
if (i == Id.size())
{
Id.push_back(token_cifa[dangqiandanci].content);
}
tok.code = 0;
tok.value = i;
token.push_back(tok);
}
break;
}
case 56://字符常量
{
int i;
for (i = 0; i < ConstChar.size(); i++)//字符常量表查重
{
if (!ConstChar[i].compare(token_cifa[dangqiandanci].content))
break;
}
if (i == ConstChar.size())
ConstChar.push_back(token_cifa[dangqiandanci].content); //插入字符串常量表并赋值
tok.value = i;
tok.code = 1;
token.push_back(tok);
break;
}
case 57://字符串常量
{
int i;
for (i = 0; i < ConstString.size(); i++)//字符串常量表查重
{
if (!ConstString[i].compare(token_cifa[dangqiandanci].content))
break;
}
if (i == ConstString.size())
ConstString.push_back(token_cifa[dangqiandanci].content); //插入字符串常量表并赋值
tok.value = i;
tok.code = 2;
token.push_back(tok);
break;
}
case 51:
case 53:
case 54://常数表
{
int i;
for (i = 0; i < ConstNum.size(); i++)//数字常量表查重
{
if (!ConstNum[i].compare(token_cifa[dangqiandanci].content))
break;
}
if (i == ConstNum.size())
ConstNum.push_back(token_cifa[dangqiandanci].content); //插入数字常量表并赋值
tok.value = i;
tok.code = 3;
token.push_back(tok);
break;
}
case 34:
{
tok.code = 5;
tok.value = 0;
token.push_back(tok);
break;
}
case 16:
{
tok.code = 6;
tok.value = 0;
token.push_back(tok);
break;
}
case 4:
{
tok.code = 7;
tok.value = 0;
token.push_back(tok);
break;
}
case 18:
{
tok.code = 8;
tok.value = 0;
token.push_back(tok);
break;
}
case 13:
{
tok.code = 9;
tok.value = 0;
token.push_back(tok);
break;
}
case 27:
{
tok.code = 10;
tok.value = 0;
token.push_back(tok);
break;
}
case 68:
{
tok.code = 11;
tok.value = 0;
token.push_back(tok);
break;
}
case 69:
{
tok.code = 12;
tok.value = 0;
token.push_back(tok);
break;
}
case 65:
{
tok.code = 13;
tok.value = 0;
token.push_back(tok);
break;
}
case 66:
{
tok.code = 14;
tok.value = 0;
token.push_back(tok);
break;
}
case 104:
{
tok.code = 15;
tok.value = 0;
token.push_back(tok);
break;
}
case 105:
{
tok.code = 16;
tok.value = 0;
token.push_back(tok);
break;
}
case 72:
{
tok.code = 17;
tok.value = 0;
token.push_back(tok);
break;
}
case 108:
{
tok.code = 18;
tok.value = 0;
token.push_back(tok);
break;
}
case 102:
{
tok.code = 19;
tok.value = 0;
token.push_back(tok);
break;
}
case 103:
{
tok.code = 20;
tok.value = 0;
token.push_back(tok);
break;
}
case 109:
{
tok.code = 21;
tok.value = 0;
token.push_back(tok);
break;
}
case 111:
{
tok.code = 22;
tok.value = 0;
token.push_back(tok);
break;
}
case 110:
{
tok.code = 23;
tok.value = 0;
token.push_back(tok);
break;
}
case 100:
{
tok.code = 24;
tok.value = 0;
token.push_back(tok);
break;
}
case 101:
{
tok.code = 25;
tok.value = 0;
token.push_back(tok);
break;
}
case 62:
{
tok.code = 26;
tok.value = 0;
token.push_back(tok);
break;
}
case 92:
{
tok.code = 27;
tok.value = 0;
token.push_back(tok);
break;
}
case 61:
{
tok.code = 28;
tok.value = 0;
token.push_back(tok);
break;
}
case 32:
{
tok.code = 29;
tok.value = 0;
token.push_back(tok);
break;
}
case 10:
{
tok.code = 30;
tok.value = 0;
token.push_back(tok);
break;
}
case 22:
{
tok.code = 31;
tok.value = 0;
token.push_back(tok);
break;
}
case 82:
{
tok.code = 32;
tok.value = 0;
token.push_back(tok);
token.push_back(tok);
break;
}
case 83:
{
tok.code = 33;
tok.value = 0;
token.push_back(tok);
token.push_back(tok);
break;
}
case 39:
{
tok.code = 34;
tok.value = 0;
token.push_back(tok);
break;
}
case 38:
{
tok.code = 35;
tok.value = 0;
token.push_back(tok);
break;
}
case 76:
{
tok.code = 36;
tok.value = 0;
token.push_back(tok);
break;
}
case 77:
{
tok.code = 37;
tok.value = 0;
token.push_back(tok);
break;
}
default:;
}
}
}
void print_token(){
keyinit();
for (int i = 0; i < token.size(); i++)
{
cout << "<";
if (i<10)printf("0");
if (i<100)printf("0");
cout << i << ">\t";
cout << "(" << token[i].code << "," << token[i].value << ")\t";
switch (token[i].code)
{
case 0:cout << "<" << Id[token[i].value] << "> " << endl; break;
case 1:cout << "<" << ConstChar[token[i].value] << "> " << endl; break;
case 2:cout << "<" << ConstString[token[i].value] << "> " << endl; break;
case 3:cout << "<" << ConstNum[token[i].value] << "> " << endl; break;
default:cout << "<" << keywords[token[i].code] << "> " << endl;
}//switch
} //for循环
}
int cifa_main()
{
printf("Start To Read A File\n");
if (duqu())
{
printf("Start To Analysis Words\n");
huaci();
zhuanma();
printf("Words Analysis\nToken:\n");
print_token();
//shuchu();
printf("Words Analysis Finished\n");
}
system("pause");
return 0;
}
int _tmain()
{
cifa_main();
cout << "Start Syntax Analysis:\n" << endl;
system("pause");
if (syntax_analysis())
{
cout << "Syntax Analysis Succeed\n" << endl;
Psynbl();
system("pause");
optimization();
system("pause");
cout << "Start Assembly:\n" << endl;
system("pause");
compilization();
duAsm();
for (int aa=0; aa < zifushu; aa++)
{
printf("%c", wenben[aa]);
}
}
else
{
cout << "Start Syntax Error And Over\n" << endl;
}
//simplePriority();
//LL1();
system("pause");
return 0;
}
void test(){
cout<<"test"<<endl;
}
|
08e66790f594e1eb2cfc2b91763f4ffe0d6d1690
|
238b81c4b46cedf4f94c0ccde4486e55602ec2be
|
/public/libgc/server/resp_processor.cpp
|
6cbb182159f2757ea975dbfa2dd7d37ec097b962
|
[] |
no_license
|
adidos/proj_repos
|
0e0641711fff7351454f9164c99176c4a21f60f8
|
07911257202c4238580f9ab4d982e99f3f5e30ea
|
refs/heads/master
| 2021-01-20T03:35:16.423273
| 2014-07-12T08:08:39
| 2014-07-12T08:08:39
| null | 0
| 0
| null | null | null | null |
WINDOWS-1252
|
C++
| false
| false
| 1,973
|
cpp
|
resp_processor.cpp
|
#include "resp_processor.h"
#include "response_manager.h"
#include "session_manager.h"
#include "client_manager.h"
#include "epoll_server.h"
#include "common/logger.h"
#include "common/index.h"
#include "common/utility.h"
RespProcessor::RespProcessor(SessionManager* pSessMgr,
ClientManager* pClientMgr) :_sess_mgr_prt(pSessMgr),
_client_mgr_prt(pClientMgr)
{
}
RespProcessor::~RespProcessor()
{
}
/**
* brief:
*
* @returns
*/
void RespProcessor::doIt()
{
char buffer[16*1024] = {'\0'};
ResponseManager* pRespMgr = ResponseManager::getInstance();
assert(NULL != pRespMgr);
while(!_terminate)
{
CmdTask resp;
bool ret = pRespMgr->getRespTask(resp);
if(!ret)
{
LOG4CPLUS_WARN(FLogger, "response array is empty.");
continue;
}
SessionBasePtr pSession = _sess_mgr_prt->getSession(resp.seqno);
if(!pSession)
{
LOG4CPLUS_ERROR(FLogger, "can't find the session by " << resp.seqno);
_sess_mgr_prt->delSession(resp.seqno);
continue;
}
int64_t uid = resp.pCmd->get_userid();
string name = resp.pCmd->get_cmd_name();
memset(buffer, '\0', 16 * 1024);
int length = resp.pCmd->header_length() + resp.pCmd->body_length();
ret = resp.pCmd->encode((byte*)buffer, length);
if(!ret)
{
LOG4CPLUS_ERROR(FLogger, "command encode failed for " << name);
continue;
}
pSession->write2Send(string(buffer, length));
int iret = pSession->sendBuffer();
uint64_t data = U64(resp.seqno, pSession->getFd());
if(SOCKET_EAGAIN == iret) //socket»º³åÇøÐ´Âú
{
_epoll_svr_ptr->notify(pSession->getFd(), data, EVENT_WRITE);
}
else if(SOCKET_ERR == iret) //socket ³ö´í
{
_epoll_svr_ptr->notify(pSession->getFd(), data, EVENT_ERROR);
_sess_mgr_prt->delSession(pSession);
_client_mgr_prt->freeClient(uid, resp.seqno);
}
LOG4CPLUS_INFO(FLogger, "TimeTace: request[" << resp.idx << "] to response["
<< name << "] spend time " << current_time_usec() - resp.timestamp);
}
}
|
b42e6987cffa804aeff6c5b8afcf65fb6f04125f
|
0f41e546cf59b389e6e657980ea1019a811b1c54
|
/hdu/fire_net.cpp
|
767a4deefa26485535c936953767119d3c836167
|
[] |
no_license
|
aim-for-better/acm
|
ef23964e02016361e9dd70cff2520cb86a57f3f4
|
6d4d939b811bb00b3f148b74f3d3b3720b61bf97
|
refs/heads/master
| 2020-07-18T03:53:15.455644
| 2017-10-30T14:26:52
| 2017-10-30T14:26:52
| 73,922,672
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,230
|
cpp
|
fire_net.cpp
|
#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
char arr[5][5];
bool visited[5][5];
int dir[][2]={0,1,0,-1,1,0,-1,0}; //r,l,d,u
int nmax;
void dfs(int pos,int num){
int x=pos/n;
int y=pos%n;
if(arr[x][y]=='X'|| visited[x][y]) return ;
int buf[4][4];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
buf[i][j]=visited[i][j];
}
visited[x][y]=true;
for(int k=0;k<4;k++){
int nx=x+dir[k][0];
int ny=y+dir[k][1];
for(;nx>=0&&nx<n&&ny>=0&&ny<n&&arr[nx][ny]!='X';nx+=dir[k][0],ny+=dir[k][1]){
visited[nx][ny]=true;
}
}
if(1+num>nmax) nmax=1+num;
for(int i=0;i<n*n;i++)dfs(i,1+num);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
visited[i][j]=buf[i][j];
return ;
}
int main()
{
while(cin>>n&&n!=0){
memset(arr,0,sizeof(arr));
memset(visited,false,sizeof(visited));
nmax=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
for(int i=0;i<n*n;i++){
dfs(i,0);
}
cout<<nmax<<endl;
}
return 0;
}
|
678c12976cca25c24ce9192a4f8cb1ea474daf28
|
992a387ba9edbdd60d018d300d3cb5c2217a7a8e
|
/2022/new-concepts/tries.cpp
|
da068dc0c7f904f87cc4a734106d57bd0390a6d3
|
[] |
no_license
|
ashishnagpal2498/CPP_Concepts_and_Codes
|
7e5f8d5a1866c3658c61a8a4b2015526ab8de38f
|
a1828c639816fd23ec9b04635e544b27a4bc27bc
|
refs/heads/master
| 2022-07-21T16:01:29.461619
| 2022-07-15T06:18:56
| 2022-07-15T06:18:56
| 167,674,604
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,018
|
cpp
|
tries.cpp
|
// Tries - DataStructure -
#include<bits/stdc++.h>
using namespace std;
class TrieNode{
public:
char data;
TrieNode** children;
bool isTerminal;
TrieNode(char d){
data = d;
children = new TrieNode*[26];
for(int i=0;i<26;i++){
children[i] = NULL;
}
isTerminal = false;
}
~TrieNode(){
delete children;
}
};
class Trie{
TrieNode* root;
void insertHelper(string s, TrieNode* root){
if(s.size() == 0){
root->isTerminal = true;
return;
}
int index = s[0] - 'a';
TrieNode* child;
if(root->children[index] != NULL){
child = root->children[index];
}
else {
child = new TrieNode(s[0]);
root->children[index] = child;
}
insertHelper(s.substr(1),child);
}
bool searchHelper(TrieNode* root, string word){
if(root == NULL) return false;
if(word.size()==0){
return root->isTerminal;
}
int index = word[0] - 'a';
return searchHelper(root->children[index],word.substr(1));
}
bool isEmptyNode(TrieNode* root){
for(int i=0;i<26;i++){
if(root->children[i]) return false;
}
return true;
}
void removeHelper(TrieNode* root,string word){
// Base case
if(word.size() == 0){
root->isTerminal = false;
return;
}
int index = word[0] - 'a';
if(root->children[index] != NULL){
removeHelper(root->children[index],word.substr(1));
if(!root->children[index]->isTerminal && isEmptyNode(root->children[index])){
TrieNode* waste = root->children[index];
root->children[index] = NULL;
delete waste;
}
}
return;
}
void printHelper(TrieNode* root, string s){
for(int i=0;i<26;i++){
TrieNode* child = root->children[i];
// Base Case ->
if(child != NULL ){
s+= child->data;
if(child->isTerminal) { cout<<s<<endl;}
printHelper(child,s);
s.pop_back();
}
}
}
public:
Trie(){
root = new TrieNode('\0');
}
void insert(string s){
// Base case;
insertHelper(s,root);
}
bool searchWord(string word){
return searchHelper(root,word);
}
void removeWord(string word){
removeHelper(root,word);
}
void printTrie(){
printHelper(root,"");
}
};
int main(){
Trie obj;
obj.insert("are");
obj.insert("as");
obj.insert("dot");
obj.insert("do");
bool ans = obj.searchWord("dot");
ans ? cout<<" Word present ": cout<<" Not present";
obj.removeWord("dot");
cout<<"\n";
ans = obj.searchWord("do");
ans ? cout<<" Word present\n": cout<<" Not present\n";
obj.printTrie();
return 0;
}
|
e71ae993a8363086aeb040321fab0236c61bcb87
|
924de80dab7907fdb03ab1cafeea6e399d9759c6
|
/PROJECTS/GAMES/MULTIPOLY/CODE/GAMEPLAY/GAME/CARD/GAMEPLAY_GAME_CARD.h
|
e8dc902c104bf14e02403be015859762694ff8b5
|
[] |
no_license
|
x-tox-man/xengine
|
866fd44d79207c71c6ad2709a66496d392ec0f6d
|
81b9445795422969848acfffde59136e1eb66fbe
|
refs/heads/master
| 2021-04-29T10:39:43.257184
| 2020-10-25T10:48:54
| 2020-10-25T10:48:54
| 77,837,329
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,692
|
h
|
GAMEPLAY_GAME_CARD.h
|
//
// GAMEPLAY_GAME_CARD.hpp
// MULTIPOLY
//
// Created by Christophe Bernard on 27/02/17.
// Copyright © 2017 cbe. All rights reserved.
//
#ifndef GAMEPLAY_GAME_CARD_hpp
#define GAMEPLAY_GAME_CARD_hpp
#include "CORE_HELPERS_CLASS.h"
#include "GAMEPLAY_COMPONENT_ENTITY.h"
#include "CORE_MATH_QUATERNION.h"
#include "GAMEPLAY_PLAYER.h"
#include "CORE_FILESYSTEM_PATH.h"
#include "GRAPHIC_SHADER_PROGRAM_DATA_PROXY.h"
#include "GAMEPLAY_SCENE.h"
#include "GRAPHIC_MESH.h"
#include "GRAPHIC_OBJECT_RESOURCE_LOADER.h"
#include "GRAPHIC_SHADER_EFFECT_LOADER.h"
#include "GRAPHIC_SHADER_EFFECT.h"
#include "GRAPHIC_OBJECT_SHAPE_PLAN.h"
#include "GRAPHIC_TEXTURE_BLOCK.h"
#include "GAMEPLAY_RULE.h"
class GAMEPLAY_PLAYER;
XS_CLASS_BEGIN_WITH_ANCESTOR(GAMEPLAY_GAME_CARD, GAMEPLAY_COMPONENT_ENTITY)
GAMEPLAY_GAME_CARD();
~GAMEPLAY_GAME_CARD();
void Initialize(
const CORE_MATH_VECTOR & position,
const CORE_MATH_VECTOR & size,
const CORE_MATH_QUATERNION & orientation,
GAMEPLAY_SCENE * scene,
GRAPHIC_TEXTURE_BLOCK * block );
void SetRule( GAMEPLAY_RULE * rule ) { Rule = rule; }
GAMEPLAY_RULE * GetRule() { return Rule; }
void SetupAnimation();
bool Update( const float step, GAMEPLAY_PLAYER * player );
bool ApplyRule( GAMEPLAY_PLAYER * player );
void ResetPosition();
private:
GAMEPLAY_RULE
* Rule;
float
AnimationTimer;
bool
RuleIsApplied;
CORE_MATH_VECTOR
AnimationStartupPosition;
CORE_MATH_QUATERNION
AnimationStartupOrientation;
XS_CLASS_END
#endif /* GAMEPLAY_GAME_CARD_hpp */
|
ef4ed335e6fae0075859c4020a828751e324e480
|
40942829eb12bde7c255cd09b4d2de929868d489
|
/NOTATRI.cpp
|
27a4d66b8cc048b57a4d10bdf29528240e2966ce
|
[] |
no_license
|
sanjana12345/Spoj-Solution
|
cccda06a34ff0feb541612e6928e8b894b21c17b
|
ce928017bdd36c86c4bafa07953bc0b263466ab7
|
refs/heads/master
| 2022-08-26T06:53:04.273589
| 2020-05-27T09:30:25
| 2020-05-27T09:30:25
| 267,261,513
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 536
|
cpp
|
NOTATRI.cpp
|
#include<bits/stdc++.h>
using namespace std;
int a[2002];
int binarysearch(int p,int q, int x)
{
while(q-p>1)
{
int b=(p+q)/2;
if(a[b]>x)
q=b;
else
p=b;
}
if(a[p]>x)
return p;
return q;
}
int main()
{
int i,j,n,b,c,d,e;
unsigned long long ans;
cin>>n;
while(n!=0)
{
ans=0;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(i=1;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if(a[i]+a[j]<a[n])
{
b=binarysearch(i,n,a[j]+a[i]);
ans=ans+n-b+1;
}
}
cout<<ans<<"\n";
cin>>n;
}
return 0;
}
|
4effcfb8a2d5ab18c41119f5a83cf76bfa916b79
|
da1500e0d3040497614d5327d2461a22e934b4d8
|
/third_party/llvm-project/compiler-rt/test/msan/fstat64.cpp
|
8e3a6d553bfcf93b252cad47834aa56a471e1d3a
|
[
"NCSA",
"MIT",
"LLVM-exception",
"Apache-2.0",
"BSD-3-Clause",
"GPL-1.0-or-later",
"LGPL-2.0-or-later"
] |
permissive
|
youtube/cobalt
|
34085fc93972ebe05b988b15410e99845efd1968
|
acefdaaadd3ef46f10f63d1acae2259e4024d383
|
refs/heads/main
| 2023-09-01T13:09:47.225174
| 2023-09-01T08:54:54
| 2023-09-01T08:54:54
| 50,049,789
| 169
| 80
|
BSD-3-Clause
| 2023-09-14T21:50:50
| 2016-01-20T18:11:34
| null |
UTF-8
|
C++
| false
| false
| 238
|
cpp
|
fstat64.cpp
|
// REQUIRES: linux
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
#include <stdlib.h>
#include <sys/stat.h>
int main(void) {
struct stat64 st;
if (fstat64(0, &st))
exit(1);
if (S_ISBLK(st.st_mode))
exit(0);
return 0;
}
|
1a5da285b45b45657fca334cc54b66a283beb334
|
19907e496cfaf4d59030ff06a90dc7b14db939fc
|
/POC/oracle_dapp/node_modules/wrtc/third_party/webrtc/include/chromium/src/third_party/WebKit/Source/core/inspector/InspectorHighlight.h
|
886851b362e238423b28e4e3ee7923e26d905ad5
|
[
"BSD-2-Clause"
] |
permissive
|
ATMatrix/demo
|
c10734441f21e24b89054842871a31fec19158e4
|
e71a3421c75ccdeac14eafba38f31cf92d0b2354
|
refs/heads/master
| 2020-12-02T20:53:29.214857
| 2017-08-28T05:49:35
| 2017-08-28T05:49:35
| 96,223,899
| 8
| 4
| null | 2017-08-28T05:49:36
| 2017-07-04T13:59:26
|
JavaScript
|
UTF-8
|
C++
| false
| false
| 2,180
|
h
|
InspectorHighlight.h
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef InspectorHighlight_h
#define InspectorHighlight_h
#include "core/CoreExport.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/LayoutRect.h"
#include "platform/graphics/Color.h"
#include "platform/heap/Handle.h"
#include "platform/inspector_protocol/TypeBuilder.h"
namespace blink {
class Color;
class JSONValue;
struct CORE_EXPORT InspectorHighlightConfig {
USING_FAST_MALLOC(InspectorHighlightConfig);
public:
InspectorHighlightConfig();
Color content;
Color contentOutline;
Color padding;
Color border;
Color margin;
Color eventTarget;
Color shape;
Color shapeMargin;
bool showInfo;
bool showRulers;
bool showExtensionLines;
bool displayAsMaterial;
String selectorList;
};
class CORE_EXPORT InspectorHighlight {
STACK_ALLOCATED();
public:
InspectorHighlight(Node*, const InspectorHighlightConfig&, bool appendElementInfo);
InspectorHighlight();
~InspectorHighlight();
static bool getBoxModel(Node*, OwnPtr<protocol::DOM::BoxModel>*);
static InspectorHighlightConfig defaultConfig();
static bool buildNodeQuads(Node*, FloatQuad* content, FloatQuad* padding, FloatQuad* border, FloatQuad* margin);
void appendPath(PassRefPtr<JSONArray> path, const Color& fillColor, const Color& outlineColor, const String& name = String());
void appendQuad(const FloatQuad&, const Color& fillColor, const Color& outlineColor = Color::transparent, const String& name = String());
void appendEventTargetQuads(Node* eventTargetNode, const InspectorHighlightConfig&);
PassRefPtr<JSONObject> asJSONObject() const;
private:
void appendNodeHighlight(Node*, const InspectorHighlightConfig&);
void appendPathsForShapeOutside(Node*, const InspectorHighlightConfig&);
RefPtr<JSONObject> m_elementInfo;
RefPtr<JSONArray> m_highlightPaths;
bool m_showRulers;
bool m_showExtensionLines;
bool m_displayAsMaterial;
};
} // namespace blink
#endif // InspectorHighlight_h
|
da701786de76a21f92270cc0f71e54288237b54d
|
1f3dd4320acfafb283266491edfb6d571b6f0e50
|
/src/client/OutputStreamImpl.h
|
4967e0f23d90b1372dcb6b684fe9d6fa03164665
|
[
"BSD-3-Clause",
"Apache-2.0"
] |
permissive
|
erikmuttersbach/libhdfs3
|
d193c6b787b33f2339a8ff73ab4356ef835ca5d3
|
9a60d79812d6dee72455f61bff57a93c3c7d56f5
|
refs/heads/apache-rpc-9
| 2020-12-25T22:58:48.860681
| 2019-11-05T00:53:35
| 2019-11-05T00:53:35
| 27,222,933
| 42
| 25
|
Apache-2.0
| 2019-11-05T00:53:36
| 2014-11-27T11:42:59
|
C++
|
UTF-8
|
C++
| false
| false
| 5,187
|
h
|
OutputStreamImpl.h
|
/********************************************************************
* Copyright (c) 2013 - 2014, Pivotal Inc.
* All rights reserved.
*
* Author: Zhanwei Wang
********************************************************************/
/********************************************************************
* 2014 -
* open source under Apache License Version 2.0
********************************************************************/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _HDFS_LIBHDFS3_CLIENT_OUTPUTSTREAMIMPL_H_
#define _HDFS_LIBHDFS3_CLIENT_OUTPUTSTREAMIMPL_H_
#include "Atomic.h"
#include "Checksum.h"
#include "DateTime.h"
#include "ExceptionInternal.h"
#include "FileSystem.h"
#include "Memory.h"
#include "OutputStreamInter.h"
#include "PacketPool.h"
#include "Permission.h"
#include "Pipeline.h"
#include "server/LocatedBlock.h"
#include "SessionConfig.h"
#include "Thread.h"
#ifdef MOCK
#include "PipelineStub.h"
#endif
namespace Hdfs {
namespace Internal {
/**
* A output stream used to write data to hdfs.
*/
class OutputStreamImpl: public OutputStreamInter {
public:
OutputStreamImpl();
~OutputStreamImpl();
/**
* To create or append a file.
* @param fs hdfs file system.
* @param path the file path.
* @param flag creation flag, can be Create, Append or Create|Overwrite.
* @param permission create a new file with given permission.
* @param createParent if the parent does not exist, create it.
* @param replication create a file with given number of replication.
* @param blockSize create a file with given block size.
*/
void open(shared_ptr<FileSystemInter> fs, const char * path, int flag,
const Permission & permission, bool createParent, int replication,
int64_t blockSize);
/**
* To append data to file.
* @param buf the data used to append.
* @param size the data size.
*/
void append(const char * buf, int64_t size);
/**
* Flush all data in buffer and waiting for ack.
* Will block until get all acks.
*/
void flush();
/**
* return the current file length.
* @return current file length.
*/
int64_t tell();
/**
* @ref OutputStream::sync
*/
void sync();
/**
* close the stream.
*/
void close();
/**
* Output a readable string of this output stream.
*/
std::string toString();
/**
* Keep the last error of this stream.
* @error the error to be kept.
*/
void setError(const exception_ptr & error);
private:
void appendChunkToPacket(const char * buf, int size);
void appendInternal(const char * buf, int64_t size);
void checkStatus();
void closePipeline();
void completeFile(bool throwError);
void computePacketChunkSize();
void flushInternal(bool needSync);
//void heartBeatSenderRoutine();
void initAppend();
void openInternal(shared_ptr<FileSystemInter> fs, const char * path, int flag,
const Permission & permission, bool createParent, int replication,
int64_t blockSize);
void reset();
void sendPacket(shared_ptr<Packet> packet);
void setupPipeline();
private:
//atomic<bool> heartBeatStop;
bool closed;
bool isAppend;
bool syncBlock;
//condition_variable condHeartBeatSender;
exception_ptr lastError;
int checksumSize;
int chunkSize;
int chunksPerPacket;
int closeTimeout;
int heartBeatInterval;
int packetSize;
int position; //cursor in buffer
int replication;
int64_t blockSize; //max size of block
int64_t bytesWritten; //the size of bytes has be written into packet (not include the data in chunk buffer).
int64_t cursor; //cursor in file.
int64_t lastFlushed; //the position last flushed
int64_t nextSeqNo;
mutex mut;
PacketPool packets;
shared_ptr<Checksum> checksum;
shared_ptr<FileSystemInter> filesystem;
shared_ptr<LocatedBlock> lastBlock;
shared_ptr<Packet> currentPacket;
shared_ptr<Pipeline> pipeline;
shared_ptr<SessionConfig> conf;
std::string path;
std::vector<char> buffer;
steady_clock::time_point lastSend;
//thread heartBeatSender;
friend class Pipeline;
#ifdef MOCK
private:
Hdfs::Mock::PipelineStub * stub;
#endif
};
}
}
#endif /* _HDFS_LIBHDFS3_CLIENT_OUTPUTSTREAMIMPL_H_ */
|
67159670e3e66d254fddddb3687aec97321fb067
|
08e02b157cd7ac94f638bd0133f40f11ead47b73
|
/src/Core/Memory.cpp
|
fd5bc0a8aa034df40b22142a2c01473f6493c550
|
[
"MIT"
] |
permissive
|
thennequin/Texeled
|
9c040993e0608321a17a493a6ca6386e40428cbe
|
538dbc078b572754c012faa34f590ccf8a971af4
|
refs/heads/master
| 2022-11-16T16:54:24.260714
| 2022-11-10T20:32:04
| 2022-11-10T20:32:04
| 176,142,597
| 66
| 5
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,952
|
cpp
|
Memory.cpp
|
#include "Core/Memory.h"
#include <stdlib.h> // malloc / free
#include <string.h> // memcpy
namespace Core
{
////////////////////////////////////////////////////////////////
// PointerVoid
////////////////////////////////////////////////////////////////
PointerVoid::PointerVoid()
{
m_iMemory = -1;
m_iSize = 0;
m_iPos = 0;
}
PointerVoid::PointerVoid(void* pMemory, size_t iSize, size_t iPos)
{
m_iMemory = (intptr_t)pMemory;
m_iSize = iSize;
m_iPos = iPos;
}
PointerVoid::PointerVoid(const PointerVoid& oRight)
{
m_iMemory = oRight.m_iMemory;
m_iSize = oRight.m_iSize;
m_iPos = oRight.m_iPos;
}
bool PointerVoid::IsRootAllocation() const
{
return m_iPos == 0;
}
bool PointerVoid::operator ==(intptr_t pRight) const
{
CORE_ASSERT(m_iMemory != -1, "Using an uninitialized Pointer");
return (m_iMemory + (intptr_t)m_iPos) == pRight;
}
bool PointerVoid::operator !=(intptr_t pRight) const
{
CORE_ASSERT(m_iMemory != -1, "Using an uninitialized Pointer");
return (m_iMemory + (intptr_t)m_iPos) != pRight;
}
PointerVoid::operator PointerVoid() const
{
return PointerVoid((void*)m_iMemory, m_iSize, m_iPos);
}
PointerVoid::operator void*() const
{
CORE_ASSERT(m_iMemory != -1, "Using an uninitialized Pointer");
return (void*)((char*)m_iMemory + m_iPos);
}
////////////////////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////////////////////
uint16_t c_iAllocMagicNumber = 0xf6b4;
CORE_PTR_VOID Malloc(size_t iSize)
{
#ifdef CORE_MEMORY_DEBUG
void* pAlloc = malloc(iSize + sizeof(uint16_t));
if (pAlloc != NULL)
{
memcpy(pAlloc, &c_iAllocMagicNumber, sizeof(uint16_t));
return PointerVoid((char*)pAlloc + sizeof(uint16_t), iSize);
}
return PointerVoid(NULL, 0);
#else
return malloc(iSize);
#endif
}
void Free(CORE_PTR_VOID pMemory)
{
#ifdef CORE_MEMORY_DEBUG
CORE_ASSERT((intptr_t)(void*)pMemory != -1, "Using an uninitialized Pointer");
CORE_ASSERT(pMemory.IsRootAllocation());
uint16_t* pAlloc = (uint16_t*)pMemory - 1;
CORE_ASSERT(*pAlloc == c_iAllocMagicNumber, "Trying to free an already free allocation");
*pAlloc = 0;
free((void*)pAlloc);
#else
free(pMemory);
#endif
}
CORE_PTR_VOID ToPointer(void* pMemory, size_t iSize)
{
CORE_ASSERT((pMemory != NULL && iSize > 0) || (pMemory == NULL && iSize == 0));
#ifdef CORE_MEMORY_DEBUG
return PointerVoid(pMemory, iSize, 0);
#else
return pMemory;
#endif
}
void MemCpy(CORE_PTR_VOID pDest, CORE_PTR_VOID pSource, size_t iSize)
{
#ifdef CORE_MEMORY_DEBUG
if (iSize > 0)
{
CORE_PTR_CAST(char, pDest) + (iSize - 1);
CORE_PTR_CAST(char, pSource) + (iSize - 1);
}
#endif
memcpy((void*)pDest, (void*)pSource, iSize);
}
void MemZero(CORE_PTR_VOID pData, size_t iSize)
{
#ifdef CORE_MEMORY_DEBUG
if (iSize > 0)
{
CORE_PTR_CAST(char, pData) + (iSize - 1);
}
#endif
memset((void*)pData, 0, iSize);
}
}
|
e8c13d8e0a340ecf62dd211a9e28b8310a9a76d2
|
1b080901551c6681e49509fac070e740526b5b0d
|
/impulse/source/impulse-0.5.1/src/parser/parsers/message.h
|
06d06040bf4cdd7ee849b6b45c4bb54a33931e03
|
[
"BSD-3-Clause"
] |
permissive
|
mikeaustin/www.mike-austin.com
|
90c4240b7f5869db47183290b2cdab58d71f949b
|
47bd99d52d6e9249ac8cd2a46e72dc70464f9eaf
|
refs/heads/master
| 2021-01-22T18:57:52.479708
| 2017-06-29T19:55:45
| 2017-06-29T19:55:45
| 85,132,420
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,055
|
h
|
message.h
|
namespace impulse { namespace parser {
//
// class MessageParser
//
void MessageParser::identifier( Express& expr, Token peek )
{
BEG( "Message::identifier( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
expr.push( new Message( *token.value().get<Symbol>() ) );
MessageParser( lexer() ).parse( expr );
END( "" );
}
void MessageParser::keyword( Express& expr, Token peek )
{
BEG( "Message::keyword( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
Express* arg1 = new Express();
expr.push( new Message( *token.value().get<Symbol>(), arg1 ) );
KeywordExpressionParser( lexer() ).parse( *arg1 );
END( "" );
}
void MessageParser::operatorx( Express& expr, Token peek )
{
BEG( "Message::operator( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
Express* arg1 = new Express( expr );
expr.push( new Message( *token.value().get<Symbol>(), arg1 ) );
BinaryExpressionParser( lexer() ).parse( *arg1 );
END( "" );
}
void MessageParser::range( Express& expr, Token peek )
{
BEG( "Message::range( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
//Express* arg1 = new Express( expr );
expr.push( new Message( *token.value().get<Symbol>(), lexer().nextToken().value() ) );
SubexprExpressionParser( lexer() ).parse( expr );
END( "" );
}
//
// class BinaryExpressionParser
//
void BinaryExpressionParser::number( Express& expr, Token peek )
{
BEG( "BinaryExpression::number( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
expr.push( token.value() );
BinaryMessageParser( lexer() ).parse( expr );
END( "" );
}
void BinaryExpressionParser::initialize( Express& expr, Token peek )
{
BEG( "BinaryExpression::initialize()" );
}
void BinaryExpressionParser::finalize( Express& expr, Token peek )
{
END( "BinaryExpression::finalize()" );
}
//
// class BinaryMessageParser
//
void BinaryMessageParser::identifier( Express& expr, Token peek )
{
BEG( "Message::identifier( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
expr.push( new Message( *token.value().get<Symbol>() ) );
BinaryMessageParser( lexer() ).parse( expr );
END( "" );
}
void BinaryMessageParser::operatorx( Express& expr, Token peek )
{
BEG( "BinaryMessage::operator( " << peek.value().inspect() << " )" );
Token token = lexer().nextToken();
Express* arg1 = new Express( expr.parent() );
expr.parent().push( new Message( *token.value().get<Symbol>(), arg1 ) );
BinaryExpressionParser( lexer() ).parse( *arg1 );
END( "" );
}
} }
|
7988e32aa3e63e947e3554ac47671d863fdd0e48
|
d3e3d0a300deca29aae01e8265bf3d72f6c0c13d
|
/study/ZombieAI.cpp
|
58a431804fdfbcac6fb53a2e0be218023f4a457b
|
[] |
no_license
|
nanaya7896/SourceFile
|
41bf546ffa7785f7a14e804c54b306fec7d2e060
|
9c6337b5b14d466956f7404a085167c04890c2b8
|
refs/heads/master
| 2021-01-17T18:17:10.205448
| 2016-10-21T02:12:30
| 2016-10-21T02:12:30
| 71,336,958
| 0
| 0
| null | 2016-10-21T02:12:31
| 2016-10-19T08:44:50
|
Logos
|
UTF-8
|
C++
| false
| false
| 865
|
cpp
|
ZombieAI.cpp
|
#include"ZombieAI.h"
CZombieAI::CZombieAI()
{
}
CZombieAI::~CZombieAI()
{
}
void CZombieAI::Update()
{
}
/*
CHASER_Mode,
DEATH_Mode,
FLOW_Mode,
WALLOW_Mode,
STAIRS_Mode,
HITSTOP_Mode
*/
void CZombieAI::ZombieAISelect(ZombieAIName name)
{
switch (name)
{
CHASER_Mode:
test(1);
break;
DEATH_Mode:
break;
FLOW_Mode:
break;
WALLOW_Mode:
break;
STAIRS_Mode:
break;
default:
break;
}
}
void CZombieAI::test(int num)
{
m_ZombieInfo[num].animNum = 2;
//if (m_ZombieInfo[num].)
if (m_pAnimation[m_ZombieInfo[num].skin][m_ZombieInfo[num].animNum]->GetAnimFinishTime() <= m_ZombieInfo[num].AnimController[m_ZombieInfo[num].animNum]->GetTime())
{
m_ZombieInfo[num].isAlive = FALSE;
value++;
CScore::GetInstnce()->SetScoreNum(value);
m_pDecorate->SetisFlash(TRUE);
Zombierevival(num);
m_pWaterSlider[num]->ResetValue();
}
}
|
f06f66e4b1f14b7283bd4cb5e1a2b057d9e1b6ac
|
d34dc5af1fdbb694f5ce0c56b9cc6108f4d355ee
|
/c++/demo/io.cpp
|
265bb8948dc4974cdc28f3f8df45373369fec185
|
[] |
no_license
|
masinfund/code
|
09faa655b4a37501683588a0f05a849ece1eed5f
|
08a012902cce40b841490db6ec21b372def1bfec
|
refs/heads/master
| 2020-04-27T20:55:53.829998
| 2019-03-09T10:45:15
| 2019-03-09T10:45:15
| 174,676,493
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,247
|
cpp
|
io.cpp
|
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <climits>
#include <cctype>
#include <array>
#include <iterator>
#include <functional> // bind
#include <typeinfo>
//对某个空指针p执行typeid(*p) throw bad_typeid
#include <initializer_list>
#include <windows.h>
#include <memory>
#include <cassert>
#include <stdexcept>
#include <deque>
#include <list>
#include <stack>
#include <forward_list>
#include <utility>
#include <locale>
#define debug puts("-----")
#define pi (acos(-1.0))
#define eps (1e-8)
#define inf (1<<30)
using namespace std;
void test01()
{
ofstream ofs("out.dat" , ios::binary | ios::app) ;
ifstream ifs("in.dat" , ios::binary ) ;
string s1 ;
getline(ifs,s1);
for(auto &ch : s1)
ch = toupper(ch) ;
ofs << s1 << endl;
ofs.close();
ifs.close() ;
}
int main(int argc, char const *argv[])
{
return 0;
}
|
2053f802f8dfec3291f0b95f97d8128e93a07dd8
|
c777564eb4ae9d2536729cdc2d2d8b00b46e63af
|
/Source/ASCII_GAME/Core/Maths/Rect.h
|
20644a443c43127c060ab4a878b04dc54515042c
|
[
"MIT"
] |
permissive
|
asimpson2004/Chip8Emulator
|
90abf1a7d56c50bb485bece40f3c51cf868b09ae
|
fffd07fc6a993ead0267a3cabd5ee076948af1d8
|
refs/heads/master
| 2022-11-12T07:32:14.463109
| 2020-07-05T16:16:13
| 2020-07-05T16:16:13
| 276,463,310
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 184
|
h
|
Rect.h
|
#ifndef _RECT_H_
#define _RECT_H_
class Rect
{
public:
Rect();
Rect(float _x, float _y, float _w, float _h);
~Rect();
float x;
float y;
float w;
float h;
private:
};
#endif
|
d2dbe686af7fa6e9202f31d2c42d676c0cb1b9ab
|
33a21a0c98ed16c1dc12b4f66417dff1dff48992
|
/astar.3pfrk.cpp
|
da71071c4d14b126b444ae97496f350f6109669f
|
[] |
no_license
|
j000/ASD2.projekt
|
cbbd6fbace71b4ccda24407171a2113246f09f4e
|
fb5d1c76f29a41aec8cfdf2cff1b3490883a3711
|
refs/heads/master
| 2020-06-01T19:35:42.903642
| 2019-06-10T01:21:15
| 2019-06-10T01:21:15
| 190,902,570
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,531
|
cpp
|
astar.3pfrk.cpp
|
#include "astar.hpp"
#include "dijkstra.hpp"
#include "Graph.hpp"
#include <cmath>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
Graph<std::pair<float, float>, double> g;
constexpr std::size_t grid_size = 16u;
const auto sqrt_2 = std::sqrt(2.);
auto zero_heuristics
= [](const Graph<std::pair<float, float>, double>& graph,
std::size_t current_vertex_id,
std::size_t end_vertex_id) -> double { return 0.; };
auto manhattan_heuristics
= [](const Graph<std::pair<float, float>, double>& graph,
std::size_t current_vertex_id,
std::size_t end_vertex_id) -> double {
const auto& v1_data = graph.vertexData(current_vertex_id);
const auto& v2_data = graph.vertexData(end_vertex_id);
return std::abs(v1_data.first - v2_data.first)
+ std::abs(v1_data.second - v2_data.second);
};
auto euclidean_heuristics
= [](const Graph<std::pair<float, float>, double>& graph,
std::size_t current_vertex_id,
std::size_t end_vertex_id) -> double {
const auto& v1_data = graph.vertexData(current_vertex_id);
const auto& v2_data = graph.vertexData(end_vertex_id);
return std::sqrt(
std::pow(v2_data.first - v1_data.first, 2u)
+ std::pow(v2_data.second - v1_data.second, 2u));
};
for (std::size_t i = 0u; i < grid_size; ++i) {
for (std::size_t j = 0u; j < grid_size; ++j) {
g.insertVertex(std::make_pair(i, j));
}
}
for (std::size_t i = 0u; i < grid_size; ++i) {
for (std::size_t j = 0u; j < grid_size - 1u; ++j) {
if (j < grid_size - 1u) {
g.insertEdge(i * grid_size + j, i * grid_size + j + 1u, 1.);
g.insertEdge(i * grid_size + j + 1u, i * grid_size + j, 1.);
}
if (i < grid_size - 1u) {
g.insertEdge(i * grid_size + j, (i + 1u) * grid_size + j, 1.);
g.insertEdge((i + 1u) * grid_size + j, i * grid_size + j, 1.);
}
if (i < grid_size - 1u && j < grid_size - 1u) {
g.insertEdge(
i * grid_size + j, (i + 1u) * grid_size + j + 1u, sqrt_2);
g.insertEdge(
(i + 1u) * grid_size + j + 1u, i * grid_size + j, sqrt_2);
g.insertEdge(
i * grid_size + j + 1u, (i + 1u) * grid_size + j, sqrt_2);
g.insertEdge(
(i + 1u) * grid_size + j, i * grid_size + j + 1u, sqrt_2);
}
}
}
for (std::size_t j = 1u; j < grid_size - 1u; ++j) {
g.removeVertex(
std::find(
g.beginVertices(),
g.endVertices(),
std::make_pair(static_cast<float>(j), grid_size / 2.f))
.id());
}
auto start_data = std::make_pair(grid_size / 2.f, 1.f);
auto end_data = std::make_pair(grid_size / 2.f + 1.f, grid_size - 1.f);
auto start_it = std::find(g.beginVertices(), g.endVertices(), start_data);
auto end_it = std::find(g.beginVertices(), g.endVertices(), end_data);
if (start_it != g.endVertices() && end_it != g.endVertices()) {
auto [shortest_path_distance, shortest_path]
= dijkstra<std::pair<float, float>, double>(
g, start_it.id(), end_it.id(), [](const double& e) -> double {
return e;
});
std::cout << "Dijkstra results:" << std::endl;
std::cout << "\tDistance: " << shortest_path_distance << std::endl;
std::cout << "\tPath (ids): ";
for (auto& v_id : shortest_path) {
std::cout << v_id << ", ";
}
std::cout << std::endl;
std::cout << "\tPath (data): ";
for (auto& v_id : shortest_path) {
std::cout << "[" << g.vertexData(v_id).first << ", "
<< g.vertexData(v_id).second << "]"
<< ", ";
}
std::cout << std::endl;
std::tie(shortest_path_distance, shortest_path)
= astar<std::pair<float, float>, double>(
g,
start_it.id(),
end_it.id(),
zero_heuristics,
[](const double& e) -> double { return e; });
std::cout << "AStar (zero) results:" << std::endl;
std::cout << "\tDistance: " << shortest_path_distance << std::endl;
std::cout << "\tPath (ids): ";
for (auto& v_id : shortest_path) {
std::cout << v_id << ", ";
}
std::cout << std::endl;
std::cout << "\tPath (data): ";
for (auto& v_id : shortest_path) {
std::cout << "[" << g.vertexData(v_id).first << ", "
<< g.vertexData(v_id).second << "]"
<< ", ";
}
std::cout << std::endl;
std::tie(shortest_path_distance, shortest_path)
= astar<std::pair<float, float>, double>(
g,
start_it.id(),
end_it.id(),
manhattan_heuristics,
[](const double& e) -> double { return e; });
std::cout << "AStar (manhattan) results:" << std::endl;
std::cout << "\tDistance: " << shortest_path_distance << std::endl;
std::cout << "\tPath (ids): ";
for (auto& v_id : shortest_path) {
std::cout << v_id << ", ";
}
std::cout << std::endl;
std::cout << "\tPath (data): ";
for (auto& v_id : shortest_path) {
std::cout << "[" << g.vertexData(v_id).first << ", "
<< g.vertexData(v_id).second << "]"
<< ", ";
}
std::cout << std::endl;
std::tie(shortest_path_distance, shortest_path)
= astar<std::pair<float, float>, double>(
g,
start_it.id(),
end_it.id(),
euclidean_heuristics,
[](const double& e) -> double { return e; });
std::cout << "AStar (euclidean) results:" << std::endl;
std::cout << "\tDistance: " << shortest_path_distance << std::endl;
std::cout << "\tPath (ids): ";
for (auto& v_id : shortest_path) {
std::cout << v_id << ", ";
}
std::cout << std::endl;
std::cout << "\tPath (data): ";
for (auto& v_id : shortest_path) {
std::cout << "[" << g.vertexData(v_id).first << ", "
<< g.vertexData(v_id).second << "]"
<< ", ";
}
std::cout << std::endl;
}
return 0;
}
|
4136b6871a3332593773fcdbd9a9a7d360cfe855
|
94a85a1b28ca1a55634490c32540241f4f60a3e6
|
/module_0/ex02/Account.class.cpp
|
77a7550101289642b97b45ff90055547d97858f1
|
[] |
no_license
|
Saske912/cpp
|
054507793021d90bb174f3039639b74f36f4f05d
|
05691dca31531b3ce865189dee2c692ba4d5f21f
|
refs/heads/master
| 2023-05-28T12:29:28.884531
| 2021-06-08T01:46:30
| 2021-06-08T01:46:30
| 353,736,381
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 5,080
|
cpp
|
Account.class.cpp
|
//##################################################################
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣠⣴⣖⣁⣀⣀⡄⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⢀⣀⣠⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣤⣄⣀⣀
// ⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠁
// ⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠁⠀
// ⠀⠀⠀⠀⠀⣼⣿⡟⠀⢠⡲⠖⠀⣿⣿⣿⣿⣿⣿⣿⣉⠁⠀⠀⠀
// ╱╱╱╱╭━╮╭╮ ⣼⣿⣿⡷⢤⠤⠤⣥⡤⣿⠿⣿⣿⣿⡿⣿⣿⣷⡀
// ╱╱╱╱┃╭╯┃┃ ⠀⣀⣠⣼⣿⣿⣿⣧⠑⠟⠀⠈⠙⠱⢦⣿⣿⣿⠁⣸⣿⣿⣇⠀
// ╭━━┳╯╰┳┫┃╭━━╮ ⠊⠉⠉⠉⠉⠩⠞⠁⠀⠀⠄⠀⠀⡴⣿⣿⣿⠗⣵⣿⠡⠉⠉⠁⠀
// ┃╭╮┣╮╭╋┫┃┃┃━┫ ⠀⢡⠀⠀⠀⢈⣾⣟⣵⣯⣼⣿⣬⣄⣀⠀⠀
// ┃╰╯┃┃┃┃┃╰┫┃━┫ ⠀⠀⣶⣶⣶⣾⣥⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀
// ┃╭━╯╰╯╰┻━┻━━╯ ⠀⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⡄
// ┃┃ ⢠⢤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⣿⣿⣿⡄
// ╰╯ ⠀⠠⣰⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠇⠀⠀⠀⠀⠀
//#################################################################
#include "Account.class.hpp"
#include <iostream>
#include <ctime>
int Account::nbAccounts = 0;
int Account::totalAmount = 0;
int Account::totalNbDeposits = 0;
int Account::totalNbWithdrawals = 0;
int Account::nbAmountCall = 0;
void Account::displayStatus( void ) const
{
displayTimestamp();
std::cout << "index:" << this->accountIndex << ';';
std::cout << "amount:" << this->amount << ';';
std::cout << "deposits:" << this->nbDeposits << ';';
std::cout << "withdrawals:" << this->nbWithdrawals << std::endl;
return ;
}
void Account::displayAccountsInfos( void )
{
displayTimestamp();
std::cout << "accounts:" << getNbAccounts() << ';';
std::cout << "total:" << getTotalAmount() << ';';
std::cout << "deposits:" << getNbDeposits() << ';';
std::cout << "withdrawals:" << getNbWithdrawals() << std::endl;
return ;
}
int Account::getNbAccounts( void )
{
return nbAccounts;
}
int Account::getTotalAmount( void )
{
return totalAmount;
}
int Account::getNbDeposits( void )
{
return totalNbDeposits;
}
int Account::getNbWithdrawals( void )
{
return totalNbWithdrawals;
}
Account::Account( int initial_deposit )
{
this->totalAmount += initial_deposit;
this->amount = initial_deposit;
this->accountIndex =this->nbAccounts;
this->nbAccounts += 1;
this->nbDeposits = 0;
this->nbWithdrawals = 0;
displayTimestamp();
std::cout << "index:" << this->accountIndex << ';';
std::cout << "amount:" << checkAmount();
std::cout << ";created" << std::endl;
return ;
}
Account::~Account( void )
{
displayTimestamp();
std::cout << "index:" << this->accountIndex;
std::cout << ";amount:" << checkAmount();
std::cout << ";closed" << std::endl;
return ;
}
Account::Account( void )
{
return ;
}
void Account::makeDeposit( int deposit )
{
displayTimestamp();
std::cout << "index:"<< this->accountIndex << ";p_amount:" << this->amount;
std::cout << ";deposit:" << deposit << ";amount:";
this->amount += deposit;
this->nbDeposits += 1;
this->totalNbDeposits += 1;
this->totalAmount += deposit;
std::cout << checkAmount() << ";nb_deposits:" << this->nbDeposits << std::endl;
return ;
}
bool Account::makeWithdrawal( int withdrawal )
{
displayTimestamp();
std::cout << "index:" << this->accountIndex << ";p_amount:";
std::cout << checkAmount() << ";withdrawal:";
if (withdrawal > checkAmount())
{
std::cout << "refused" << std::endl;
return false;
}
else
{
std::cout << withdrawal;
this->amount -= withdrawal;
this->totalAmount -= withdrawal;
this->totalNbWithdrawals += 1;
this->nbWithdrawals += 1;
std::cout << ";amount:" << checkAmount() << ";nb_withdrawals:";
std::cout << this->nbWithdrawals << std::endl;
}
return true;
}
int Account::checkAmount( void ) const
{
const_cast< Account * >( this )->nbAmountCall++;
return this->amount;
}
void Account::displayTimestamp( void )
{
time_t tim;
char buffer [80];
struct tm * timeinfo;
time(&tim);
timeinfo = localtime(&tim);
strftime (buffer,80,"%Y%m%d_%H%M%S",timeinfo);
std::cout << "[" << buffer << "] ";
}
|
55791d2eb0bf460c8cb744777dc35c209d3c2ee2
|
6822829627ff78514736f5bd9475b8ef0e10acfc
|
/Homework_8/grocery.cpp
|
3f09ed1b280384171f59acf0d106214200e1eebe
|
[] |
no_license
|
ChadFunckes/CU_Denver_CSCI2421
|
f845943aedd2a9083518e5e759a97ca3a806425f
|
272f0314bdf3a093b7ed0f7077db4a6dcb1f4edd
|
refs/heads/master
| 2021-01-17T15:06:24.032070
| 2016-06-23T02:48:36
| 2016-06-23T02:48:36
| 31,835,790
| 0
| 0
| null | null | null | null |
MacCentralEurope
|
C++
| false
| false
| 4,124
|
cpp
|
grocery.cpp
|
// FILE: grocery.cxx
// A small test program to test the simulate function for series of grocery store line.
#include <iostream> // Provides cout
#include <vector> // Provides vector
#include <cstdlib> // Provides EXIT_SUCCESS
#include <queue> // Provides queue
#include "grocery.h" // Provides averager, bool_source, washer
using namespace std;
using namespace main_savitch_8A;
void simulate
(double arrival_prob, unsigned int total_time);
// Precondition: 0 <= arrival_prob <= 1.
// Postcondition: The function has simulated a grocery where arrival_prob
// is the probability of a customer arriving in any second, and total_time
// is the total number of seconds for the simulation.
// After the simulation, the function two pieces of information to cout:
// (1) The number of cars washed
// (2) The average waiting time of a customer.
int main( )
{
simulate(0.25, 6000);
return EXIT_SUCCESS;
}
void simulate
(double arrival_prob, unsigned int total_time)
// Library facilities used: iostream, queue, washing.h
{
washer machine[5]; // creates 5 machines
averager wait_times[5]; // creates 5 wait time counters
vector<queue<unsigned int> > arrival_times; // Waiting customerís time stamps
for (unsigned i = 0; i < 5; i++) { // push 5 queues into the vector with random process times
arrival_times.push_back(queue<unsigned int>());
machine[i].set_time(rand()% 600+10);
}
unsigned int next; // A value taken from the queue
bool_source arrival(arrival_prob);
unsigned int current_second;
unsigned int line_length = 0;
unsigned int short_line;
// Write the parameters to cout.
for (unsigned i = 0; i < 5; i++){
cout << "Seconds register " << i <<" takes to finish " << machine[i].get_time() << endl;
}
cout << "Probability of customer arrival during a second: ";
cout << arrival_prob << endl;
cout << "Total simulation seconds: " << total_time << endl << endl;
for (current_second = 1; current_second <= total_time; ++current_second)
{ // Simulate the passage of one second of time.
// Check whether a new customer has arrived.
if (arrival.query()){
short_line = 0; // set shortest line to line 0 by default
line_length = arrival_times[0].size(); // set shortest comparison length to line 0 by default
// find the shortest line to place the person into
if (arrival_times[1].size() < arrival_times[2].size() && arrival_times[1].size() < line_length){
line_length = arrival_times[1].size();
short_line = 1;
}
else if (arrival_times[2].size() < arrival_times[3].size() && arrival_times[2].size() < line_length){
line_length = arrival_times[2].size();
short_line = 2;
}
else if (arrival_times[3].size() < arrival_times[4].size() && arrival_times[3].size() < line_length){
line_length = arrival_times[3].size();
short_line = 3;
}
else if (arrival_times[4].size() < line_length){ // line 4 will get the peron if no lines are shorter than 1
line_length = arrival_times[4].size();
short_line = 4;
}
// put the person in the shortest line
arrival_times[short_line].push(current_second);
}
for (unsigned i = 0; i < 5; i++){
// Check whether we can start another checkout.
if ((!machine[i].is_busy()) && (!arrival_times[i].empty()))
{
next = arrival_times[i].front();
arrival_times[i].pop();
wait_times[i].next_number(current_second - next);
machine[i].start_washing();
}
// Tell the register to simulate the passage of one second.
machine[i].one_second();
}
}
// Write the summary information about the simulation.
unsigned int total = 0;
unsigned int avg = 0;
for (unsigned int i = 0; i < 5; i++){
cout << "Customers served in line " << i << ": " << wait_times[i].how_many_numbers() << endl;
total = total + wait_times[i].how_many_numbers();
if (wait_times[i].how_many_numbers() > 0){
cout << "Average wait: " << wait_times[i].average() << " sec" << endl;
avg = avg + wait_times[i].average();
}
}
avg = avg / 5;
cout << "Total served: " << total << endl;
cout << "Total average: " << avg << endl;
}
|
57b3fcf2542a8a007fd13dae537b5df6c2c82df7
|
868f30e81e44c2bfc75c4eadc21c455bda68fb6a
|
/dlg/ZImgeSelect.cpp
|
8f588599dc2c3d73f29d7eb8a5d1a2deeb77aba8
|
[] |
no_license
|
BGCX261/zmessanger-hg-to-git
|
8ed5220d762fb660dd06f51cbcd6ce672c2e28e2
|
03384d2cbf061eddb0672a85e74e6c44acebbbb8
|
refs/heads/master
| 2021-01-19T22:32:54.683969
| 2010-09-09T10:53:31
| 2010-09-09T10:53:31
| 41,378,152
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 6,570
|
cpp
|
ZImgeSelect.cpp
|
//
// Project: zMessanger (zIM)
//
// Version: 0.3
//
// Description: ICQ client for MOTOMAGX Platform.
// In future planed support XMPP protocol.
//
// Author: Ant-ON <prozanton@gmail.com>, (C) 2009-2010
//
#include "ZImgeSelect.h"
#include "ZXStatusText.h"
#include <qlabel.h>
#include <ZApplication.h>
#include <ZSoftKey.h>
#include "config.h"
#include "zEmoticon.h"
#include "zgui.h"
#include "zDefs.h"
ZImgeSelect::ZImgeSelect(bool _smile, bool _addHotStatus)
:MyBaseDlg()
{
smile = _smile;
addHotStatus = _addHotStatus;
myWidget = new ZWidget ();
softKey = new ZSoftKey ( NULL, this, this );
softKey->setText ( ZSoftKey::LEFT, LNG_OK, ( ZSoftKey::TEXT_PRIORITY )0 );
softKey->setClickedSlot ( ZSoftKey::RIGHT, this, SLOT ( slotLeftSoftKey()) );
if (smile)
{
setMainWidgetTitle(LNG_SMYLESEL);
iconView = new ZIconView(this, NULL, 0, zSmile->getSmileCount()-NO_SMILE, ZSkinService::clsZIconView2);
iconView->setShowLabel(false);
for ( uint i = NO_SMILE; i < zSmile->getSmileCount(); i++ )
{
ZIconViewItem *item = new ZIconViewItem(iconView);
item->setPixmap(zSmile->getEmotIcon(i), false, false);
item->setPixmapRect(QRect(0,0,25,25));
}
#if ( defined(NEW_PLATFORM) && !defined(CUTED_PLATFORM) )
iconView->setItemSizeFixed(true);
iconView->setItemSize(QSize(25, 25));
#endif
iconView->setLayout(5,8);
iconView->setCurrentItem(iconView->item(oldSmile));
softKey->setClickedSlot ( ZSoftKey::LEFT, this, SLOT ( slotImegeSelected() ) );
connect ( iconView, SIGNAL ( returnPressed(ZIconViewItem*) ), this, SLOT ( lbSmileSel(ZIconViewItem*) ) );
setContentWidget ( iconView );
softKey->setText ( ZSoftKey::RIGHT, LNG_CANCEL, ( ZSoftKey::TEXT_PRIORITY )0 );
} else
{
setMainWidgetTitle("xStatus");
init_strings_maps();
tabWidget = new ZNavTabWidget(myWidget);
lbStatus = new ZListBox ( QString ( "%I16%M" ), tabWidget, 0);
lbStatus->setFixedWidth ( SCREEN_WIDTH );
QPixmap pm;
for (int i=0;i<38;i++)
{
pm.load( ProgDir + "/status/icq/x/icq_xstatus" + QString::number(i-1) + ".png" );
ZSettingItem* listitem = new ZSettingItem(lbStatus, QString("%I16%M") );
listitem->setPixmap ( 0, pm );
listitem->appendSubItem ( 1, QString::fromUtf8(x_status2string(i).c_str()) , true );
lbStatus->insertItem ( listitem, -1, true );
}
connect ( lbStatus, SIGNAL ( selected ( int ) ), this, SLOT ( lbStatusSel ( int ) ) );
pm.load(ProgDir+ "/menu/xStatus.png");
tabWidget->addTab(lbStatus, QIconSet(pm), "");
if ( !addHotStatus )
{
lbQuickStatus = new ZListBox ( QString ( "%I16%M" ), tabWidget, 0);
lbQuickStatus->setFixedWidth ( SCREEN_WIDTH );
ZConfig cfg(ProgDir+"/QuickXStatus.cfg");
lbQuickStatus->clear();
QString st;
int nst;
for (int i=1;i<20;i++)
{
nst = cfg.readNumEntry(QString("QuickXStatus"), QString("Status"+QString::number(i)), -1);
if (nst > -1)
{
pm.load( ProgDir + "/status/icq/x/icq_xstatus" + QString::number(nst-1) + ".png" );
ZSettingItem* listitem = new ZSettingItem(lbQuickStatus, QString("%I16%M") );
listitem->setPixmap ( 0, pm );
st = cfg.readEntry(QString("QuickXStatus"), QString("Text"+QString::number(i)), "") + " "+cfg.readEntry(QString("QuickXStatus"), QString("Desc"+QString::number(i)), "");
if (st.length()>30)
{
st.remove(30,st.length());
st = st + "...";
}
listitem->appendSubItem ( 1, st , false );
listitem->setReservedData ( i );
lbQuickStatus->insertItem ( listitem,-1,true );
} else
{
break;
}
}
connect ( lbQuickStatus, SIGNAL ( selected ( int ) ), this, SLOT ( lbQStatusSel ( int ) ) );
pm.load(ProgDir+ "/image/tab_private.png");
tabWidget->addTab(lbQuickStatus, QIconSet(pm), "");
connect(tabWidget,SIGNAL(currentChanged(QWidget* )),this,SLOT(slotPageChanged(QWidget* )));
} else
slotPageChanged(NULL);
softKey->setClickedSlot ( ZSoftKey::LEFT, this, SLOT ( lbStatusSel ( int ) ) );
setContentWidget ( tabWidget );
lbStatus->setFocus();
}
setCSTWidget ( softKey );
}
ZImgeSelect::~ZImgeSelect()
{
delete myWidget;
myWidget=NULL;
}
void ZImgeSelect::lbStatusSel(int i)
{
if ( addHotStatus && i==0 )
accept();
if( i == 0)
{
zgui->icq->setXStatus(i,"", "");
} else
if ( i>=0 )
{
ZXStatusText * dlgXStatusText = new ZXStatusText(i, addHotStatus);
dlgXStatusText->exec();
delete dlgXStatusText;
dlgXStatusText = NULL;
}
accept();
}
void ZImgeSelect::lbQStatusSel(int n)
{
if ( n>=0 )
{
ZSettingItem* listitem = (ZSettingItem*)lbQuickStatus->item ( n );
int i = listitem->getReservedData();
ZConfig cfg(ProgDir+"/QuickXStatus.cfg");
int idStatus = cfg.readNumEntry(QString("QuickXStatus"), QString("Status"+QString::number(i)), -1);
QString statTitle = cfg.readEntry(QString("QuickXStatus"), QString("Text"+QString::number(i)), "");
QString statDesc = cfg.readEntry(QString("QuickXStatus"), QString("Desc"+QString::number(i)), "");
#ifdef _SupportZPlayer
if ( statDesc == "%nowPlaying%" )
{
zgui->icq->setXStatus(idStatus, statTitle.utf8().data(), "");
zgui->startPlayerChenel();
}
else
{
zgui->icq->setXStatus(idStatus, statTitle, statDesc);
zgui->stopPlayerChenel();
}
#else
zgui->icq->setXStatus(idStatus, statTitle, statDesc);
#endif
}
accept();
}
void ZImgeSelect::slotPageChanged(QWidget* )
{
int i = tabWidget->currentPageIndex();
switch (i)
{
case 0:
{
softKey->setClickedSlot( ZSoftKey::LEFT, this, SLOT( lbStatusChange() ) );
softKey->setText ( ZSoftKey::RIGHT, LNG_CANCEL, ( ZSoftKey::TEXT_PRIORITY )0 );
break;
}
case 1:
{
softKey->setClickedSlot( ZSoftKey::LEFT, this, SLOT( lbQStatusChange() ) );
softKey->setText ( ZSoftKey::RIGHT, LNG_ADD, ( ZSoftKey::TEXT_PRIORITY )0 );
break;
}
}
}
void ZImgeSelect::lbQStatusChange()
{
lbQStatusSel(lbQuickStatus->currentItem());
}
void ZImgeSelect::lbStatusChange()
{
lbStatusSel(lbStatus->currentItem());
}
void ZImgeSelect::lbSmileSel(ZIconViewItem * item)
{
if ( item )
{
int i = item->index();
emit addSmile(zSmile->getEmotStr(NO_SMILE+i, false));
oldSmile = i;
}
accept();
}
void ZImgeSelect::slotImegeSelected()
{
lbSmileSel(iconView->currentItem());
}
void ZImgeSelect::slotLeftSoftKey()
{
if ( !smile && !addHotStatus && tabWidget->currentPageIndex()==1 )
{
ZImgeSelect * dlg = new ZImgeSelect(smile, !addHotStatus);
dlg->exec();
delete dlg;
dlg = NULL;
return;
}
reject();
}
|
7002bbd1a9663bea5b16efa0d01fe01d74bbd2e7
|
a7cf10df662b66f2c152e739bca80c7c7e9c3ec8
|
/Assignment2/DeusExMachina.h
|
6cfa81729c15cce0967588c27aa1a74080dcb86a
|
[
"MIT"
] |
permissive
|
choidongkyu/cplus_study
|
e72bad9e9328d68e9bf10f5a476d575be791873d
|
1b0554d5bbf5aeb831de3747426457d4b33bdb76
|
refs/heads/master
| 2022-04-23T17:08:20.494557
| 2020-04-05T18:23:04
| 2020-04-05T18:23:04
| 232,004,199
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 440
|
h
|
DeusExMachina.h
|
#pragma once
#include "Vehicle.h"
using namespace std;
namespace assignment2
{
class DeusExMachina
{
public:
static DeusExMachina* GetInstance();
~DeusExMachina();
void Travel() const;
bool AddVehicle(Vehicle* vehicle);
bool RemoveVehicle(unsigned int i);
const Vehicle* GetFurthestTravelled() const;
private:
DeusExMachina();
static DeusExMachina* mDeusExMachina;
Vehicle* mVehicles[10];
size_t mVehicleCount;
};
}
|
20772df36ea780a2bc9f4b61931d521a8452550c
|
5146b09937c316af95b8692aad5fac57004c1a39
|
/cpp/GildedRoseUnitTests.cc
|
8157daf6d838ae168a41f12a0bd6eca346123c44
|
[
"MIT"
] |
permissive
|
hoxensu/GildedRose-Refactoring-Kata
|
842a69bf25976d1e717d0d12366e2beb05214d71
|
3c923efbb59a13262149059376f528bcc7888164
|
refs/heads/master
| 2021-03-20T13:15:25.681451
| 2020-03-14T07:12:00
| 2020-03-14T07:12:00
| 247,209,367
| 0
| 0
|
MIT
| 2020-03-14T04:10:12
| 2020-03-14T04:10:12
| null |
UTF-8
|
C++
| false
| false
| 4,648
|
cc
|
GildedRoseUnitTests.cc
|
#include <gtest/gtest.h>
#include "GildedRose.h"
TEST(GildedRoseTest, NormalItem) {
vector<Item> items;
items.push_back(Item("+5 Dexterity Vest", 0, 0));
items.push_back(Item("+5 Dexterity Vest", 0, 1));
items.push_back(Item("+5 Dexterity Vest", 0, 2));
items.push_back(Item("+5 Dexterity Vest", 0, 3));
items.push_back(Item("+5 Dexterity Vest", 1, 0));
items.push_back(Item("+5 Dexterity Vest", 1, 1));
items.push_back(Item("+5 Dexterity Vest", 1, 2));
GildedRose app(items);
app.updateQuality();
EXPECT_EQ(0, app.items[0].quality);
EXPECT_EQ(0, app.items[1].quality);
EXPECT_EQ(0, app.items[2].quality);
EXPECT_EQ(1, app.items[3].quality);
EXPECT_EQ(0, app.items[4].quality);
EXPECT_EQ(0, app.items[5].quality);
EXPECT_EQ(1, app.items[6].quality);
}
TEST(GildedRoseTest, AgedItem) {
vector<Item> items;
items.push_back(Item("Aged Brie", 0, 0));
items.push_back(Item("Aged Brie", 0, 50));
items.push_back(Item("Aged Brie", 1, 0));
items.push_back(Item("Aged Brie", 1, 50));
GildedRose app(items);
app.updateQuality();
EXPECT_EQ(1, app.items[0].quality);
EXPECT_EQ(50, app.items[1].quality);
EXPECT_EQ(1, app.items[2].quality);
EXPECT_EQ(50, app.items[3].quality);
}
TEST(GildedRoseTest, BackstageItem) {
vector<Item> items;
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 0, 0));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 0, 50));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 5, 47));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 5, 48));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 5, 49));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 5, 50));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 10, 48));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 10, 49));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 10, 50));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 11, 49));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 11, 50));
GildedRose app(items);
app.updateQuality();
EXPECT_EQ(0, app.items[0].quality);
EXPECT_EQ(0, app.items[1].quality);
EXPECT_EQ(50, app.items[2].quality);
EXPECT_EQ(50, app.items[3].quality);
EXPECT_EQ(50, app.items[4].quality);
EXPECT_EQ(50, app.items[5].quality);
EXPECT_EQ(50, app.items[6].quality);
EXPECT_EQ(50, app.items[7].quality);
EXPECT_EQ(50, app.items[8].quality);
EXPECT_EQ(50, app.items[9].quality);
EXPECT_EQ(50, app.items[10].quality);
}
TEST(GildedRoseTest, ConjuredItem) {
vector<Item> items;
items.push_back(Item("Conjured Mana Cake", 0, 0));
items.push_back(Item("Conjured Mana Cake", 0, 1));
items.push_back(Item("Conjured Mana Cake", 0, 2));
items.push_back(Item("Conjured Mana Cake", 0, 3));
items.push_back(Item("Conjured Mana Cake", 0, 4));
items.push_back(Item("Conjured Mana Cake", 0, 5));
items.push_back(Item("Conjured Mana Cake", 1, 0));
items.push_back(Item("Conjured Mana Cake", 1, 1));
items.push_back(Item("Conjured Mana Cake", 1, 2));
items.push_back(Item("Conjured Mana Cake", 1, 3));
GildedRose app(items);
app.updateQuality();
EXPECT_EQ(0, app.items[0].quality);
EXPECT_EQ(0, app.items[1].quality);
EXPECT_EQ(0, app.items[2].quality);
EXPECT_EQ(0, app.items[3].quality);
EXPECT_EQ(0, app.items[4].quality);
EXPECT_EQ(1, app.items[5].quality);
EXPECT_EQ(0, app.items[6].quality);
EXPECT_EQ(0, app.items[7].quality);
EXPECT_EQ(0, app.items[8].quality);
EXPECT_EQ(1, app.items[9].quality);
}
TEST(GildedRoseTest, SulfurasItem) {
vector<Item> items;
items.push_back(Item("Sulfuras, Hand of Ragnaros", 0, 80));
items.push_back(Item("Sulfuras, Hand of Ragnaros", 1, 80));
GildedRose app(items);
app.updateQuality();
EXPECT_EQ(80, app.items[0].quality);
EXPECT_EQ(80, app.items[1].quality);
EXPECT_EQ(0, app.items[0].sellIn);
EXPECT_EQ(1, app.items[1].sellIn);
}
void example()
{
vector<Item> items;
items.push_back(Item("+5 Dexterity Vest", 10, 20));
items.push_back(Item("Aged Brie", 2, 0));
items.push_back(Item("Elixir of the Mongoose", 5, 7));
items.push_back(Item("Sulfuras, Hand of Ragnaros", 0, 80));
items.push_back(Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
items.push_back(Item("Conjured Mana Cake", 3, 6));
GildedRose app(items);
app.updateQuality();
}
|
406b838105599c5f4326debd2561e14be8475883
|
23918d407cbcf5977da0505206ac4ad815e47835
|
/spatial_mix/src/spikes/test_stan.cpp
|
54d8094217cda46d33a190d9dfc57e46586c71d4
|
[] |
no_license
|
mberaha/spatial_mixtures
|
5ed5735671529f9ff1e91b9d4c812b89a936d6f3
|
96cdba90fc5d2167d44776074657a5860e6a74d7
|
refs/heads/master
| 2023-08-19T07:27:16.593276
| 2021-09-13T08:51:09
| 2021-09-13T08:51:09
| 216,822,967
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 495
|
cpp
|
test_stan.cpp
|
#include <iostream>
#include <stan/math/prim/mat.hpp>
#include <random>
int main() {
Eigen::VectorXd mean(2);
mean << 0, 10;
std::mt19937_64 rng;
Eigen::MatrixXd var(2, 2);
var << 1, 0.5, 0.5, 1;
Eigen::VectorXd normalMat = stan::math::multi_normal_rng(mean, var, rng);
std::cout << "normalMat = \n"
<< normalMat
<< std::endl;
double x = stan::math::normal_rng(0.0, 1.0, rng);
std::cout << "x = " << x << std::endl;
return 1;
}
|
599b297fa6a6da84ed49d5bc73ad7ef28d353d67
|
447e824ca0111d087f74b079747c523659f54215
|
/trivia-Project/Server/GameRequestHandler.cpp
|
1681ec9e2dfc0ff8037ce66bde1c8b5e0ec86289
|
[] |
no_license
|
yego163/Portfolio-Avi
|
03c9b7469802c2e47c3c16cbd4859875d24e4070
|
d7d409144da4d1f5aa0cb43ff1a854b7c479f644
|
refs/heads/main
| 2023-05-05T12:16:49.747585
| 2021-05-09T20:58:59
| 2021-05-09T20:58:59
| 365,840,488
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 6,824
|
cpp
|
GameRequestHandler.cpp
|
#include "GameRequestHandler.h"
GameRequestHandler::GameRequestHandler(RequestHandlerFactory* fac, LoggedUser user, Game* game, Room room) : m_game(game), m_room(room)
{
m_handlerFactory = fac;
m_user = user;
/*std::thread t(&GameRequestHandler::checkPlayersInGame, this);
t.detach();*/
}
GameRequestHandler::~GameRequestHandler()
{
}
bool GameRequestHandler::isRequestRelevant(RequestInfo inf)
{
return inf.id == LEAVE_GAME_ID || inf.id == GET_QUESION_ID || inf.id == SUBMIT_ANSWER_ID || inf.id == GET_GAME_RESULT_ID || inf.id == CLOSE_GAME_ID;
}
RequestResult GameRequestHandler::handleRequest(RequestInfo inf)
{
RequestResult reqRes;
JsonResponsePacketSerializer ResponsePacket;
if (isRequestRelevant(inf))
{
switch (inf.id)
{
case GET_GAME_RESULT_ID:
{
reqRes = getGameResults(inf);
break;
}
case GET_QUESION_ID: {
reqRes = getQuestion(inf);
break;
}
case SUBMIT_ANSWER_ID: {
reqRes = submitAnswer(inf);
break;
}
case LEAVE_GAME_ID: {
reqRes = leaveGame(inf);
break;
}
case CLOSE_GAME_ID: {
reqRes = deleteGameAndRoom();
break;
}
default:
break;
}
}
else
{
ErrorResponse erorr = ErrorResponse();
erorr.message = "The Request is not Relevant";
reqRes.newHandler = m_handlerFactory->createMenuRequestHandler(m_user);
reqRes.response = ResponsePacket.serializeErrorResponse(erorr);
}
return reqRes;
}
Room GameRequestHandler::getGameRoom()
{
return m_room;
}
RequestResult GameRequestHandler::getGameResults(RequestInfo inf)
{
RequestResult reqRes;
GetGameResultsResponse res;
int thisUserAnswerOnAllQuesions = 0;
try
{
std::vector<PlayerResults> PlayersRes;
std::vector<Game*> games = m_handlerFactory->getGameManager().getM_games();
std::map<LoggedUser, GameData> players = games.at(m_game->getId())->getPlayers();
for (std::map<LoggedUser, GameData>::iterator it1 = players.begin(); it1 != players.end(); it1++)
{
try
{
games.at(m_game->getId())->getQuestionForUser(it1->first);
}
catch (const std::invalid_argument& e)
{
if (std::string(e.what()) == "player answer on all quesions")
{
thisUserAnswerOnAllQuesions++;
PlayersRes.push_back(PlayerResults{ it1->first.getUserName(), it1->second.correctAnswerCount, it1->second.wrongAnswerCount, it1->second.averangeAnswerTime });
}
}
}
if (thisUserAnswerOnAllQuesions == players.size())
{
for (auto var : players)
{
m_handlerFactory->getDb()->setNewStatistics(m_room.getRoomData().getQuestionCount(), var.second.correctAnswerCount, var.second.averangeAnswerTime, var.first.getUserName());//set the result answers
}
res.status = OK;
res.results = PlayersRes;
reqRes.newHandler = this;
}
else
{
reqRes.newHandler = this;
res.status = ERR;
res.results = std::vector<PlayerResults>();
}
reqRes.response = JsonResponsePacketSerializer::serializeResponse(res);
}
catch (const std::exception& e)//failed
{
ErrorResponse erorr = ErrorResponse();
erorr.message = e.what();
reqRes.response = JsonResponsePacketSerializer::serializeErrorResponse(erorr);
reqRes.newHandler = this;
}
return reqRes;
}
RequestResult GameRequestHandler::getQuestion(RequestInfo inf)
{
RequestResult reqRes;
GetQuestionResponse res;
try
{
m_game->getQuestionForUser(m_user);
std::map<LoggedUser, GameData> players = m_game->getPlayers();
for (std::map<LoggedUser, GameData>::iterator it1 = players.begin(); it1 != players.end(); it1++)
if (it1->first.getUserName() == m_user.getUserName())
{
res.question = it1->second.correntQuestion.getQuestion();
std::vector<std::string> PossibleAnswers = it1->second.correntQuestion.getPossibleAnswers();
for (size_t i = 0; i < PossibleAnswers.size(); i++)
res.answers.insert(res.answers.begin(), std::pair<unsigned int, std::string>(i, PossibleAnswers[i]));
}
res.status = OK;
reqRes.newHandler = this;
reqRes.response = JsonResponsePacketSerializer::serializeResponse(res);
}
catch (const std::exception& e)//failed
{
if (std::strcmp(e.what(), "player answer on all quesions") == 0) // if the game end Properly
{
GameData dataOnUser = m_game->getPlayers()[m_user.getUserName()];
res.status = ERR;
res.question = "";
res.answers = std::map<unsigned int, std::string>();
reqRes.newHandler = this;
reqRes.response = JsonResponsePacketSerializer::serializeResponse(res);
}
else // if the game Crash
{
ErrorResponse erorr = ErrorResponse();
erorr.message = e.what();
reqRes.response = JsonResponsePacketSerializer::serializeErrorResponse(erorr);
reqRes.newHandler = m_handlerFactory->createMenuRequestHandler(m_user);
}
}
return reqRes;
}
RequestResult GameRequestHandler::submitAnswer(RequestInfo inf)
{
RequestResult reqRes;
SubmitAnswerResponse res;
try
{
SubmitAnswerRequest ans = JsonRequestPacketDeserializer::deserializeSubmitAnswer(inf.buffer);
std::map<LoggedUser, GameData> players = m_game->getPlayers();
for (std::map<LoggedUser, GameData>::iterator it = players.begin(); it != players.end(); it++)
if (it->first.getUserName() == m_user.getUserName())
res.correctAnswerId = it->second.correntQuestion.num_correctAnswer;
m_game->submitAnswer(m_user, ans.answerId);
res.status = OK;
reqRes.response = JsonResponsePacketSerializer::serializeResponse(res);
}
catch (const std::exception& e)//failed
{
ErrorResponse erorr = ErrorResponse();
erorr.message = e.what();
res.status = ERR;
reqRes.response = JsonResponsePacketSerializer::serializeErrorResponse(erorr);
}
reqRes.newHandler = this;
return reqRes;
}
RequestResult GameRequestHandler::leaveGame(RequestInfo inf)
{
RequestResult reqRes;
LeaveGameResponse res;
try
{
m_game->removePlayer(m_user);
res.status = OK;
reqRes.response = JsonResponsePacketSerializer::serializeResponse(res);
}
catch (const std::exception& e)//failed
{
ErrorResponse erorr = ErrorResponse();
erorr.message = e.what();
res.status = ERR;
reqRes.response = JsonResponsePacketSerializer::serializeErrorResponse(erorr);
}
reqRes.newHandler = m_handlerFactory->createMenuRequestHandler(m_user);
return reqRes;
}
RequestResult GameRequestHandler::deleteGameAndRoom()
{
RequestResult reqRes;
CloseRoomResponse res;
res.status = OK;
m_handlerFactory->getGameManager().deleteGame(m_game->getId());
m_handlerFactory->getRoomManager().deleteRoom(m_room.getRoomData().getId());
reqRes.newHandler = m_handlerFactory->createMenuRequestHandler(m_user);
reqRes.response = JsonResponsePacketSerializer::serializeResponse(res);
return reqRes;
}
|
0d6ac211267c774863cd27441133a3453835c1a1
|
171939de0a904c90f9af198b8e5d65f8349429d7
|
/CQ-00198/traffic/traffic.cpp
|
491b6742e7d663963ad016c969cafab2549d2afb
|
[] |
no_license
|
LittleYang0531/CQ-CSP-S-2021
|
2b1071bbbf0463e65bfc177f86a44b7d3301b6a9
|
1d9a09f8fb6bf3ba22962969a2bac18383df4722
|
refs/heads/main
| 2023-08-26T11:39:42.483746
| 2021-10-23T14:45:45
| 2021-10-23T14:45:45
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,946
|
cpp
|
traffic.cpp
|
#include<bits/stdc++.h>
using namespace std;
#define MAXN 300005
typedef long long LL;
const LL INF=0x3f3f3f3f3f3f3f3f;
template<typename _T>
void read(_T &x){
_T f=1;x=0;char s=getchar();
while('0'>s||s>'9'){if(s=='-')f=-1;s=getchar();}
while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
x*=f;
}
int n,m,T,a[505][505],b[505][505],head[MAXN],tot,col[2005],val[2005];
LL dis[MAXN],dp[2][(1<<18)+5];
struct tann{
LL t;int id;tann(){t=id=0;}
tann(LL T,int I){t=T;id=I;}
bool operator < (const tann &rhs)const{return t>rhs.t;}
};
struct edge{int to,nxt,paid;}e[MAXN<<2];
void addEdge(int u,int v,int w){e[++tot]=(edge){v,head[u],w};head[u]=tot;}
int Id(int x,int y){return x*(m+1)+y+1;}
priority_queue<tann>q;
int main(){
freopen("traffic.in","r",stdin);
freopen("traffic.out","w",stdout);
read(n);read(m);read(T);
for(int i=1;i<n;i++)for(int j=1;j<=m;j++)read(a[i][j]);
for(int i=1;i<=n;i++)for(int j=1;j<m;j++)read(b[i][j]);
for(int i=1;i<=T;i++){
int K;read(K);
if(K<=2&&m>10){
if(K==0){puts("0");continue;}
int xid,wx,cx;read(wx);read(xid);read(cx);
if(K==1){puts("0");continue;}
int yid,wy,cy;read(wy);read(yid);read(cy);
if(xid>yid)swap(wx,wy),swap(xid,yid),swap(cx,cy);
if(cx==cy){puts("0");continue;}
for(int j=1;j<n;j++)
for(int k=1;k<=m;k++)
addEdge(Id(j,k-1),Id(j,k),a[j][k]),
addEdge(Id(j,k),Id(j,k-1),a[j][k]);
for(int j=1;j<=n;j++)
for(int k=1;k<m;k++)
addEdge(Id(j-1,k),Id(j,k),b[j][k]),
addEdge(Id(j,k),Id(j-1,k),b[j][k]);
for(int j=1;j<=Id(n,m);j++)dis[j]=INF;
while(!q.empty())q.pop();LL res=min(1ll*wx,1ll*wy);
for(int j=1;j<m;j++)if(j<xid||j>=yid)dis[Id(0,j)]=0,q.push((tann){0LL,Id(0,j)});
for(int j=1;j<n;j++)if(j+m<xid||j+m>=yid)dis[Id(j,m)]=0,q.push((tann){0LL,Id(j,m)});
for(int j=1;j<m;j++)if(j+m+n<xid||j+m+n>=yid)dis[Id(n,m-j)]=0,q.push((tann){0LL,Id(n,m-j)});
for(int j=1;j<n;j++)if(j+m+m+n<xid||j+m+m+n>=yid)dis[Id(n-j,0)],q.push((tann){0LL,Id(n-j,0)});
while(!q.empty()){
tann t=q.top();q.pop();if(dis[t.id]!=t.t)continue;int u=t.id;
//if(u%100==0)printf("dis[%d]:%lld\n",u,dis[u]);
for(int j=head[u];j;j=e[j].nxt){
int v=e[j].to,w=e[j].paid;//printf("%d-->%d %d\n",u,v,w);
if(dis[u]+1ll*w<dis[v])dis[v]=dis[u]+1ll*w,q.push((tann){dis[v],v});
}
}
for(int j=1;j<m;j++)if(j>=xid&&j<yid)res=min(res,dis[Id(0,j)]);
for(int j=1;j<n;j++)if(j+m>=xid&&j+m<yid)res=min(res,dis[Id(j,m)]);
for(int j=1;j<m;j++)if(j+m+n>=xid&&j+m+n<yid)res=min(res,dis[Id(n,m-j)]);
for(int j=1;j<n;j++)if(j+m+m+n>=xid&&j+m+m+n<yid)res=min(res,dis[Id(n-j,0)]);
printf("%lld\n",res);
for(int j=1;j<=Id(n,m);j++)head[j]=0;tot=0;continue;
}
LL res=INF;
for(int j=1;j<=n+n+m+m;j++)val[j]=col[j]=0;
for(int j=1;j<=K;j++){
int w,id,c;read(w);read(id);read(c);
val[id]=w;col[id]=c;
}
for(int j=0;j<(1<<m);j++)dp[0][j]=INF;dp[0][0]=0;int now=0,las=1;
for(int j=1;j<=n;j++)
for(int k=1;k<=m;k++){
swap(now,las);int tmp0=0,tmp1=0;
for(int l=0;l<(1<<m);l++)dp[now][l]=INF;
if(j==1){if(col[k])tmp0+=val[k];else tmp1+=val[k];}
if(k==m){if(col[j+m])tmp0+=val[j+m];else tmp1+=val[j+m];}
if(j==n){if(col[m-k+1+m+n])tmp0+=val[m-k+1+m+n];else tmp1+=val[m-k+1+m+n];}
if(k==1){if(col[n-j+1+m+n+m])tmp0+=val[n-j+1+m+n+m];else tmp1+=val[n-j+1+m+n+m];}
//printf("point %d %d:%d %d\n",j,k,tmp0,tmp1);
for(int l=0;l<(1<<m);l++){
int tp0=tmp0,tp1=tmp1;
if(l&(1<<k-1))tp0+=a[j-1][k];else tp1+=a[j-1][k];
if(k>1){if(l&(1<<k-2))tp0+=b[j][k-1];else tp1+=b[j][k-1];}
int S1=l|(1<<k-1),S2=l&((1<<m)-1-(1<<k-1));
dp[now][S1]=min(dp[now][S1],dp[las][l]+1ll*tp1);
dp[now][S2]=min(dp[now][S2],dp[las][l]+1ll*tp0);
}
//printf("dp[%d][%d]:%d\n",j,k,dp[now][(1<<m)-1]);
//for(int l=0;l<(1<<m);l++)printf("dp[%d][%d][%d]:%d\n",j,k,l,dp[now][l]);
}
for(int j=0;j<(1<<m);j++)res=min(res,dp[n+m+1&1][j]);
printf("%lld\n",res);
}
return 0;
}
|
6982405d965c14c96705fa01eeb7e65a41f1a026
|
7b08283d294593b2161e3ab8bdbc51549cfc643c
|
/src/World.cpp
|
901131836a769c748d016eff53323cac81a80da1
|
[
"MIT"
] |
permissive
|
kwangsing3/Asteroid-GE-archive-
|
7be2bd314a048b1a25260fe9b4f83e8c03fb1ff4
|
a982293ab3f7652eff923bfdc2931836c9f9d60e
|
refs/heads/master
| 2020-12-31T23:49:03.955628
| 2020-02-08T07:00:52
| 2020-02-08T07:00:52
| 191,006,911
| 0
| 0
| null | null | null | null |
BIG5
|
C++
| false
| false
| 9,633
|
cpp
|
World.cpp
|
#include <World.hpp>
#include <Camera.hpp>
#include <Window.hpp>
#include <SceneManager.hpp>
extern unsigned int Window_Width, Window_Height;
void World::_Pivot::CreateMouseCollision()
{
_needdebug = true;
if (this->_visable)
{
colshape.clear();
btCollisionShape* _shap;
_shap = new btCapsuleShapeX(0.2f, 0.55f * (1 + this->_actor->transform->scale.x));
colshape.push_back(_shap);
world_this->m_collisionShapes.push_back(_shap);
_shap = new btCapsuleShape(0.2f, 0.55f * (1 + this->_actor->transform->scale.x));
colshape.push_back(_shap);
world_this->m_collisionShapes.push_back(_shap);
_shap = new btCapsuleShapeZ(0.2f, 0.55f * (1 + this->_actor->transform->scale.x));
colshape.push_back(_shap);
world_this->m_collisionShapes.push_back(_shap);
btTransform startTransform[3]; startTransform[0].setIdentity(); startTransform[1].setIdentity(); startTransform[2].setIdentity();
btQuaternion quat;
//quat.setEuler(-glm::radians(this->_actor->transform->rotation.y), glm::radians(this->_actor->transform->rotation.x), glm::radians(this->_actor->transform->rotation.z));//or quat.setEulerZYX depending on the ordering you want
quat.setEulerZYX(glm::radians(this->_actor->transform->rotation.z), glm::radians(-this->_actor->transform->rotation.y), glm::radians(this->_actor->transform->rotation.x));
startTransform[0].setOrigin(btVector3(this->_actor->transform->position.x + .5f, this->_actor->transform->position.y, this->_actor->transform->position.z));
startTransform[1].setOrigin(btVector3(this->_actor->transform->position.x, this->_actor->transform->position.y + .5f, this->_actor->transform->position.z));
startTransform[2].setOrigin(btVector3(this->_actor->transform->position.x, this->_actor->transform->position.y, this->_actor->transform->position.z + .5f));
for (int i = 0; i < 3; i++)
{
btVector3 localInertia(0, 0, 0);
btScalar mass(0);
startTransform[i].setRotation(quat);
bool isDynamic = (mass != 0.f);
if (isDynamic)
colshape[i]->calculateLocalInertia(mass, localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform[i]);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colshape[i], localInertia);
this->body[i] = new btRigidBody(rbInfo);
//body[0]->setCenterOfMassTransform(startTransform[0]);
body[i]->_ActorInBullet = this->_actor;
Collision_flag = _needdebug ? 4 : btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT;
body[i]->setCollisionFlags(Collision_flag);
world_this->m_dynamicsWorld->addRigidBody(body[i], _group, _mask);
}
}
}
void World::_Pivot::UpdateCollision()
{
DeleteCollision();
CreateMouseCollision();
}
void World::_Pivot::DeleteCollision()
{
world_this->depose_init_PhysicsProgress();
if (this->body[0] != NULL)world_this->m_dynamicsWorld->removeRigidBody(body[0]);
if (this->body[1] != NULL)world_this->m_dynamicsWorld->removeRigidBody(body[1]);
if (this->body[2] != NULL)world_this->m_dynamicsWorld->removeRigidBody(body[2]);
}
void World::_Pivot::AddCollision()
{
CreateMouseCollision();
}
#include <stb_image.h>
unsigned int loadCubemap(std::vector<std::string> faces)
{
unsigned int textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
int width, height, nrChannels;
for (unsigned int i = 0; i < faces.size(); i++)
{
unsigned char* data = stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0);
if (data)
{
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
stbi_image_free(data);
}
else
{
std::cout << "Cubemap texture failed to load at path: " << faces[i] << std::endl;
stbi_image_free(data);
}
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
return textureID;
}
void World::initPhysics()
{
createEmptyDynamicsWorld();
GLDebugDrawer* _deb = new GLDebugDrawer();
_deb->setDebugMode(GLDebugDrawer::DBG_FastWireframe);
this->m_dynamicsWorld->setDebugDrawer(_deb);
if(_piv!=NULL) delete _piv;
_piv = new _Pivot(new Actor(),this);
_editorCamera = new Camera(glm::vec3(0.0f, 0.0f, 3.0f));
_SceneManager = new SceneManager(this);
}
void World::init_PhysicsProgress()
{
InitPhysics = false;
depose_init_PhysicsProgress();
for (int i = 0; i < this->m_dynamicsWorld->getNumCollisionObjects(); i++)
{
if (this->m_dynamicsWorld->getCollisionObjectArray()[i]->_ActorInBullet->transform->name == "Pivot")
continue;
_PhysicsProgress.push_back(new _PhysicsStruct(i, this->m_dynamicsWorld->getCollisionObjectArray()[i]->_ActorInBullet, false));
}
}
void World::depose_init_PhysicsProgress()
{
if (_PhysicsProgress.empty()) return;
for (int i = 0; i < _PhysicsProgress.size(); i++)
{
this->m_dynamicsWorld->getCollisionObjectArray()[_PhysicsProgress[i]->_index]->_ActorInBullet = _PhysicsProgress[i]->_actor;
}
_PhysicsProgress.clear();
InitPhysics = true;
}
void World::CreateDepthMap()
{
// Point Light Depth Cubemap Texture
glGenFramebuffers(1, &depthMapFBO_PoLight);
glGenTextures(1, &depthCubemap);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap);
for (unsigned int i = 0; i < 6; ++i)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// attach depth texture as FBO's depth buffer
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO_PoLight);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthCubemap, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glGenFramebuffers(1, &depthMapFBO_DirLight);
// Directional Light Depth Texture
glGenTextures(1, &depthTexture_DirLight);
glBindTexture(GL_TEXTURE_2D, depthTexture_DirLight);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
float borderColor[] = { 1.0, 1.0, 1.0, 1.0 };
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
// attach depth texture as FBO's depth buffer
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO_DirLight);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture_DirLight, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void World::UpdateFrame()
{
_SceneManager->CheckReloadShader();
//Pyhscis Pipeline
if (this->_PlayMode)
{
if (InitPhysics) init_PhysicsProgress();
this->m_dynamicsWorld->stepSimulation(1.f / 60.0f, 1);
/* 需要特別處理一下,BulletEngine不知道為何會把我放的Pointer刷新 所以只好在刷新之前提取我做的標記 在秒數更新後依照Actor順序移動,然後再複寫回去 ps.再複寫回去是為了下次能夠再取得一次
製作一個Funcition 專門在繪製前initPhysics, 用struct儲存index以及提前抽取actor, 然後只需要依照此struct進行索引然後改變物體位置。
之後再停止模擬時複寫回去 */
for (int i = 0; i < _PhysicsProgress.size(); i++)
{
if (_PhysicsProgress[i]->Static) continue;
_PhysicsProgress[i]->_actor->transform->MoveByPhysics(&this->m_dynamicsWorld->getCollisionObjectArray()[_PhysicsProgress[i]->_index]->getWorldTransform());
}
}
else
{
if (!_PhysicsProgress.empty()) depose_init_PhysicsProgress();
}
_SceneManager->vec_SpecializedDraw(); //只需要畫一次的非普通場景特殊繪製 (座標軸、Axis ... etc)
this->m_dynamicsWorld->debugDrawWorld();
glCullFace(GL_FRONT);
///Shadw
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
if (_RenderShadow && !_SceneManager->vec_DirectionlLight.empty())
{
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO_DirLight);
glClear(GL_DEPTH_BUFFER_BIT);
_SceneManager->DrawScene(RenderShadowType::DirectionalLight);
}
if (false && !_SceneManager->vec_PointLight.empty())
{
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO_PoLight);
glClear(GL_DEPTH_BUFFER_BIT);
_SceneManager->DrawScene(RenderShadowType::PointLight);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glCullFace(GL_BACK);
// Draw Pipeline
glViewport(0, 0, Window_Width, Window_Height);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_CUBE_MAP, depthCubemap); */
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, depthTexture_DirLight);
//ImGui::Image((void*)depthTexture_DirLight,ImVec2(300,300));
/* */
if (!_SceneManager->vec_ObjectsToRender.empty() || !_SceneManager->vec_ObjectsToRender_Instancing.empty())
_SceneManager->DrawScene(RenderShadowType::Normal); //False 代表沒有在渲染陰影
}
|
61385340fc2b260bf12d239ec02123a543ffa8c2
|
8406743c27fbfa2ba2ee623497a748067c7cd236
|
/estetimage/src/include/notifications.hpp
|
edde56513213d4a3fa9dd3dcf784fabfbd3e8387
|
[] |
no_license
|
sayanel/ESTETIMAGE_PTUT
|
087479c5d86f7e528e4c75d86189d75378cd1e94
|
d63d957b1a517d8a21c01ae80c733a9b9ac1ab29
|
refs/heads/master
| 2021-01-10T04:07:48.720580
| 2015-05-25T16:14:54
| 2015-05-25T16:14:54
| 36,240,742
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 242
|
hpp
|
notifications.hpp
|
#pragma once
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <gphoto2/gphoto2-camera.h>
void error_func (GPContext *, const char *, va_list , void *);
void message_func (GPContext *, const char *, va_list, void *);
|
53cb2557dbba52ad3f193e0f9b7fdde80fd3e3b0
|
828a0516fb6900639ba7a51c6a6ceeb61796f598
|
/source/camera/camera.h
|
500ee25326e3cddc6b45f926f885e5af6dbeea82
|
[] |
no_license
|
leoburgos/engine_old
|
960b8afb26b06a8a1f5c5e8840076774ccfebc79
|
e89673ed494e654e8acba6ce5be61f7b27d673b8
|
refs/heads/master
| 2021-09-06T14:50:35.550927
| 2018-01-31T20:03:46
| 2018-01-31T20:03:46
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,159
|
h
|
camera.h
|
#pragma once
class CCamera {
VEC3 pos; // eye
VEC3 target;
VEC3 up_aux;
// 3 orthonormals axis in world space
VEC3 front;
VEC3 up;
VEC3 left;
// Prepective params
float fov_vertical; // in radians!!
float z_near;
float z_far;
float aspect_ratio;
// Matrix
MAT44 view;
MAT44 proj;
MAT44 view_proj;
void updateViewProj();
public:
//
VEC3 getPosition() const { return pos; }
VEC3 getTarget() const { return target; }
VEC3 getFront() const { return front; }
VEC3 getUp() const { return up; }
VEC3 getLeft() const { return left; }
// -------------------------------------
MAT44 getView() const {
return view;
}
MAT44 getProjection() const {
return proj;
}
MAT44 getViewProjection() const {
return view_proj;
}
// -------------------------------------
float getFov() const { return fov_vertical; }
float getZNear() const { return z_near; }
float getZFar() const { return z_far; }
//
void lookAt(VEC3 new_pos, VEC3 new_target, VEC3 new_up_aux = VEC3(0, 1, 0));
void setPerspective(float new_fov_vertical, float new_z_near, float new_z_far );
};
|
8d1da2eb18005b1e097f386d4219d6fa478e9231
|
e9b325d8572f05cd7a6db974afac864d4f8112eb
|
/algorithm_structure/heap/heap.h
|
26ee106e27188d143bd133204493cfbc5d904c3c
|
[] |
no_license
|
CXinsect/Daily_Learning
|
78abe46fbc4228ca419e43d42f4e659bafe6df86
|
4e1baa947915d58b4bb8ecc487817f1276c0d88c
|
refs/heads/master
| 2020-04-27T06:41:12.469818
| 2020-04-26T08:46:10
| 2020-04-26T08:46:10
| 174,115,582
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 784
|
h
|
heap.h
|
#pragma once
#include "array.cpp"
class heap
{
public:
heap() {}
heap(int capicaty) {
array b(capicaty);
a = b;
}
~heap() {}
private:
//获取父亲结点下标
int parent(int index) {
return (index - 1)/2;
}
//获取左孩子结点下标
int leftChild(int index) {
return index * 2 + 1;
}
//获取右孩子结点下标
int rightChild(int index) {
return index * 2 + 2;
}
//获取最大值
int getMax() {
int ret = a.get(0);
return ret;
}
//向堆中添加元素
void SiftUp(int index);
//从堆中获取最大值
void SiftDown(int index);
public:
void add(int el);
int exMax();
void print();
void Free();
private:
array a;
};
|
482df71eb74437249bc0e6e31c0f073f17a70829
|
f576eacfd93e5db78dcaaf5199a430e5a7b0ce47
|
/MP3Player.cpp
|
29013128ad9b8ca5cbc49c6f8e0a66dde7d904e8
|
[] |
no_license
|
AKQuaternion/Spring2014CS342DesignPatterns
|
00f47ca77d547e82e76a3bd6f693243175d81a27
|
5acf001e07fc28d379226a7e416a0908f9710c4a
|
refs/heads/master
| 2021-01-23T11:50:26.380353
| 2014-05-02T21:21:06
| 2014-05-02T21:21:06
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 712
|
cpp
|
MP3Player.cpp
|
//
// MP3Player.cpp
// CS394State
//
// Created by Chris Hartman on 4/1/13.
// Copyright (c) 2013 Chris Hartman. All rights reserved.
//
#include "MP3Player.h"
#include <iostream>
using std::cout;
MP3Player::MP3Player(unique_ptr<MP3PlayerState> state):_state(std::move(state))
{}
void MP3Player::pushPlayButton()
{
_state->pushPlay(this);
}
void MP3Player::pushSourceButton()
{
_state->pushSource(this);
}
void MP3Player::setState(unique_ptr<MP3PlayerState> s)
{
_state = std::move(s);
}
void MP3Player::changeRadioStation()
{
cout << "Changing radio station\n";
}
void MP3Player::playMP3()
{
cout << "Playing MP3\n";
}
void MP3Player::stopMP3()
{
cout << "Stopping MP3\n";
}
|
8d195af267dbe4d4caf820068b9b77b532775049
|
fcab6942912e1e75628238599411f46126654a80
|
/project/typetable/typetable.h
|
c362fcc9e55913226d65ab2e56fc43b18860506e
|
[] |
no_license
|
Mpandura/Dependency-Based-Code-Publisher
|
5f4af2ba79c16402e198cb3619bc4ef08c2b85d1
|
5a04b704893ef15514bf4fe930e62847b00cfb4a
|
refs/heads/master
| 2021-09-03T06:17:14.971792
| 2018-01-06T08:57:06
| 2018-01-06T08:57:06
| 116,468,579
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,126
|
h
|
typetable.h
|
#pragma once
#include "../Parser/ActionsAndRules.h"
#include<iostream>
#include<stack>
#pragma warning (disable : 4101)
namespace CodeAnalysis {
class Tuple
{
public:
using Type_name = std::string;
using Namespace_name = std::string;
using File_name = std::string;
Tuple() {};
Tuple(std::string typ, std::string nmespce, std::string fle) : type_of(typ), namespace_of(nmespce), file_of(fle) {};// Tuple is created using a initializer sequence
bool setType(Type_name); //sets the type of the tuple
bool setNamespace(Namespace_name); //sets the namespace of the tuple
bool setFile(File_name); //sets the file name to which the type belongs to
std::string getType(); //returns the type of the tuple
std::string getNamespace(); //returns the namespace of the tuple
std::string getFileName(); //returns the file name to which the type belongs to
private:
Type_name type_of;
Namespace_name namespace_of;
File_name file_of;
};
using Key = std::string;
using Keys = std::vector<Key>;
class TypeTable
{
public:
using SPtr = std::shared_ptr<ASTNode>;
TypeTable();
~TypeTable();
Keys getKeys(); //Returns all the keys in the TypeTable
bool insert(Key, std::vector< Tuple>); //inserts a tuple into the TypeTable
std::vector<Tuple> value(Key); //Returns a tuple for a key in the TypeTable
int count(); //Count of number of entries in the TypeTable
std::unordered_map<std::string, std::vector<Tuple>>& getTable(); //Returns a TypeTable Reference
void doTableAnal(); // Creates the typeTable
private:
std::string correct_namespace;
std::stack<std::string> nameSpaceStack; //stack to record the name spaces
void pushIntoMap(ASTNode* pNode); // pushes required AST nodes into the TypeTable
void DFS(ASTNode* pNode); //Walks the Abstract Syntax tree in a Depth First Serach way
bool doDisplay1(ASTNode* pNode); //checks for the required types
AbstrSynTree& ASTref_;
std::unordered_map<std::string, std::vector<Tuple>> T_Table;
std::string pType;
};
}
|
fd32feaecdc52cf47bcc492040e90e78f8c73fe7
|
b4e1d16c276be34c0548c01d8fb69bb3b91d9964
|
/Atum/Support/Spark/Extensions/Emitters/SPK_SphericEmitter.cpp
|
22b23cdb3eed45ec42fd4cb64267aee17ca17592
|
[
"Zlib"
] |
permissive
|
ENgineE777/Atum
|
034b884abf115fbdbd5dbbacddd27353044923cb
|
3e9417e2a7deda83bf937612fd070566eb932484
|
refs/heads/master
| 2023-01-11T23:22:15.010417
| 2020-11-14T07:12:09
| 2020-11-14T07:12:09
| 86,157,927
| 23
| 4
|
Zlib
| 2019-05-01T06:20:27
| 2017-03-25T13:06:05
|
C++
|
UTF-8
|
C++
| false
| false
| 5,052
|
cpp
|
SPK_SphericEmitter.cpp
|
//
// SPARK particle engine
//
// Copyright (C) 2008-2011 - Julien Fryer - julienfryer@gmail.com
// Copyright (C) 2017 - Frederic Martin - fredakilla@gmail.com
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
#include <SPARK_Core.h>
#include "Extensions/Emitters/SPK_SphericEmitter.h"
namespace SPK
{
const float SphericEmitter::PI = 3.1415926535897932384626433832795f;
SphericEmitter::SphericEmitter(
const Vector3D& direction,
float angleMin,
float angleMax,
const Ref<Zone>& zone,
bool full,
int tank,
float flow,
float forceMin,
float forceMax) :
Emitter(zone,full,tank,flow,forceMin,forceMax)
{
setDirection(direction);
setAngles(angleMin,angleMax);
}
SphericEmitter::SphericEmitter(const SphericEmitter& emitter) :
Emitter(emitter)
{
setDirection(emitter.direction);
setAngles(emitter.angleMin,emitter.angleMax);
}
void SphericEmitter::setDirection(const Vector3D& dir)
{
direction = dir;
direction.normalize();
transformDir(tDirection,direction);
computeMatrix();
}
void SphericEmitter::setAngles(float angleMin,float angleMax)
{
if (angleMax < angleMin)
{
SPK_LOG_WARNING("SphericEmitter::setAngles(float,float) - angleMin is higher than angleMax - Values are swapped");
std::swap(angleMin,angleMax);
}
angleMin = std::min(2.0f * PI,std::max(0.0f,angleMin));
angleMax = std::min(2.0f * PI,std::max(0.0f,angleMax));
this->angleMin = angleMin;
this->angleMax = angleMax;
cosAngleMin = std::cos(angleMin * 0.5f);
cosAngleMax = std::cos(angleMax * 0.5f);
}
void SphericEmitter::computeMatrix()
{
if (!tDirection.normalize())
SPK_LOG_WARNING("SphericEmitter::computeMatrix() - The direction is a null vector");
if ((tDirection.x == 0.0f)&&(tDirection.y == 0.0f))
{
matrix[0] = tDirection.z;
matrix[1] = 0.0f;
matrix[2] = 0.0f;
matrix[3] = 0.0f;
matrix[4] = tDirection.z;
matrix[5] = 0.0f;
matrix[6] = 0.0f;
matrix[7] = 0.0f;
matrix[8] = tDirection.z;
}
else
{
Vector3D axis;
crossProduct(tDirection,Vector3D(0.0f,0.0f,1.0f),axis);
float cosA = tDirection.z;
float sinA = -axis.getNorm();
axis /= -sinA;
float x = axis.x;
float y = axis.y;
float z = axis.z;
matrix[0] = x * x + cosA * (1.0f - x * x);
matrix[1] = x * y * (1.0f - cosA) - z * sinA;
matrix[2] = tDirection.x;
matrix[3] = x * y * (1.0f - cosA) + z * sinA;
matrix[4] = y * y + cosA * (1.0f - y * y);
matrix[5] = tDirection.y;
matrix[6] = x * z * (1.0f - cosA) - y * sinA;
matrix[7] = y * z * (1.0f - cosA) + x * sinA;
matrix[8] = tDirection.z;
}
}
void SphericEmitter::generateVelocity(Particle& particle,float speed) const
{
float a = SPK_RANDOM(cosAngleMax,cosAngleMin);
float theta = std::acos(a);
float phi = SPK_RANDOM(0.0f,2.0f * PI);
float sinTheta = std::sin(theta);
float x = sinTheta * std::cos(phi);
float y = sinTheta * std::sin(phi);
float z = std::cos(theta);
particle.velocity().x = speed * (matrix[0] * x + matrix[1] * y + matrix[2] * z);
particle.velocity().y = speed * (matrix[3] * x + matrix[4] * y + matrix[5] * z);
particle.velocity().z = speed * (matrix[6] * x + matrix[7] * y + matrix[8] * z);
}
void SphericEmitter::innerUpdateTransform()
{
Emitter::innerUpdateTransform();
transformDir(tDirection,direction);
computeMatrix();
}
void SphericEmitter::innerImport(const IO::Descriptor& descriptor)
{
Emitter::innerImport(descriptor);
const IO::Attribute* attrib = NULL;
if ((attrib = descriptor.getAttributeWithValue("direction")))
setDirection(attrib->getValue<Vector3D>());
if ((attrib = descriptor.getAttributeWithValue("angles")))
{
std::vector<float> tmpAngles = attrib->getValues<float>();
if (tmpAngles.size() == 2)
setAngles(tmpAngles[0],tmpAngles[1]);
else
SPK_LOG_ERROR("SphericEmitter::innerImport(const IO::Descriptor&) - Wrong number of angles : " << tmpAngles.size());
}
}
void SphericEmitter::innerExport(IO::Descriptor& descriptor) const
{
Emitter::innerExport(descriptor);
descriptor.getAttribute("direction")->setValue(getDirection());
float tmpAngles[2] = {angleMin,angleMax};
descriptor.getAttribute("angles")->setValues(tmpAngles,2);
}
}
|
19910aa4516aa3d116a6d844fdc11636e17e0088
|
066fca52e8dfb65baecd0e6e8a5bb7724590385c
|
/src/core_util/config_vars.cpp
|
d190c671b3dc76929112579c7135d0f4cd2c93cc
|
[
"MIT"
] |
permissive
|
nsdrozario/clashing-countries
|
05e27b4f32c686eb7b0ce0b0bab430d924f14350
|
b42d0cd88642951d7f75cd45c74b70ac93f05df5
|
refs/heads/master
| 2023-02-06T14:06:26.878692
| 2020-12-25T05:25:26
| 2020-12-25T05:25:26
| 284,347,577
| 0
| 0
|
NOASSERTION
| 2020-10-08T02:46:21
| 2020-08-01T22:14:59
|
C++
|
UTF-8
|
C++
| false
| false
| 410
|
cpp
|
config_vars.cpp
|
#include <clashingcountries/core_util/config_vars.hpp>
const std::vector<std::string> settings_ints {
"screen_width",
"screen_height"
};
const std::vector<std::string> settings_bools {
"fullscreen"
};
const std::vector<std::string> settings_strings {
};
std::map<std::string, int> int_settings;
std::map<std::string, bool> bool_settings;
std::map<std::string, std::string> string_settings;
|
7c67e448f6987e5e8b1842e89d6ce79bf1b4a294
|
041d4521b9a490711b411827a06c0c84504948b4
|
/Classes/lines/Lines.hpp
|
0669673729ce2d83d5875ff8f1cd344b5ee1a39a
|
[] |
no_license
|
shunter55/slotmachine
|
0afdddd2112bc166e8358f292330cbeff6440d05
|
b57c2c9651f772ffc2423970b240cc91cb661e54
|
refs/heads/master
| 2020-11-29T05:41:38.996055
| 2019-12-30T21:52:24
| 2019-12-30T21:52:24
| 230,035,545
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 335
|
hpp
|
Lines.hpp
|
//
// Lines.hpp
// slotmachine-mobile
//
// Created by Stephen Kobata on 12/23/19.
//
#ifndef Lines_hpp
#define Lines_hpp
#include <stdio.h>
#include "Line.hpp"
class Lines {
public:
Lines();
static const int TOTAL_LINES = 25;
static const std::string lineDefs[];
Line *lines[25];
};
#endif /* Lines_hpp */
|
27b85274131bc8bc08cc733c4cad6ea3b814d271
|
cf81c267f29dab0e1bdf39854e84f8e8b0d9392e
|
/src/AppRegistry.h
|
02edd8b0ee959ea5b276cecb9198038b8f4cbb91
|
[
"Apache-2.0"
] |
permissive
|
RogerParkinson/vortex-manipulator
|
840f449c663e630ece3bf667ced36df0b6e0a889
|
133989143f3f931ae8cdf7865ee34dff58039e2b
|
refs/heads/master
| 2021-06-19T08:17:43.424063
| 2021-01-29T22:38:34
| 2021-01-29T22:38:34
| 32,247,073
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,367
|
h
|
AppRegistry.h
|
/*
* AppRegistry.h
*
* Created on: 23/05/2013
* Author: roger
*/
#ifndef APPREGISTRY_H_
#define APPREGISTRY_H_
#include "App.h"
#include <Logger.h>
#define MAX_APPS 10
//#define DEBUG_APPREGISTRY
class AppRegistry {
private:
Logger *loggerAppRegistry;
int count=0;
App *apps[MAX_APPS];
App *currentApp=NULL;
const char *m_menuName = PSTR("Menu");
public:
AppRegistry();
void setCurrentApp(App *app) {
if (app == NULL) {
Serial.println(PSTR("warning: AppRegistry:setCurrentApp(NULL)"));
return;
}
if (app == currentApp) {
return; // do nothing if we are already there
}
currentApp = app;
loggerAppRegistry->debug(PSTR("switching to: %s"),app->getName());
app->setup();
loggerAppRegistry->debug(PSTR("setup complete for: %s"),app->getName());
};
const char* getMenuName() {
return m_menuName;
}
void jumpToMenu() {
loggerAppRegistry->debug(PSTR("AppRegistry: jump to menu"));
if (currentApp != NULL) {
if (strcmp(currentApp->getName(),m_menuName)==0) {
return; // already on the menu
}
currentApp->close();
}
setCurrentApp(getApp(m_menuName));
}
App *getCurrentApp() {return currentApp;};
void registerApp(App *app);
App *getApp(const char* name);
App *getApp(int i);
void init();
int getAppCount();
virtual ~AppRegistry();
};
extern AppRegistry Appregistry;
#endif /* APPREGISTRY_H_ */
|
3d80edaee2996d4ec1d193bbe8bc30949e4aefdb
|
5ed390298d2f738a6dff9628ed24a2f78e05218f
|
/app/src/main/cpp/OpenCVLearn.cpp
|
5d5e13706e2fef9adacf1ef8222632f296e799a4
|
[] |
no_license
|
tianshaokai/OpenCVLearn
|
6fd4984a1d7e3831f53680f284ad82691495a6f0
|
0f4d91b4157775bfc8a272929bad4e5b3b8f6a3f
|
refs/heads/master
| 2021-07-12T16:44:58.996302
| 2020-06-26T15:21:24
| 2020-06-26T15:21:24
| 165,164,269
| 3
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 14,220
|
cpp
|
OpenCVLearn.cpp
|
#include <jni.h>
#include <string>
#include "opencv2/opencv.hpp"
#include "android_log.h"
#include "FaceDetector.h"
#include "BitmapMatUtil.h"
using namespace cv;
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_gray
(JNIEnv *env, jclass, jintArray buf, jint w, jint h) {
//获取图片矩阵数组
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if(srcBuf == NULL) {
return 0;
}
int size = w * h;
//CV_8UC4--创建--8位无符号的四通道---带透明色的RGB图像
Mat srcImg(h, w, CV_8UC4, (unsigned char *) srcBuf);
Mat grayImage;
cvtColor(srcImg, grayImage, COLOR_BGRA2GRAY);
cvtColor(grayImage, srcImg, COLOR_GRAY2BGRA);
//申请整形数组,这个数组可以返回给java使用。注意,这里不能用new或者malloc函数代替。
//因为new出来的空间还在c中,java是不能直接使用的。
jintArray result = env->NewIntArray(size);
//将C的数组拷贝给java中的数组
env->SetIntArrayRegion(result, 0, size, srcBuf);
//释放c数组资源
env->ReleaseIntArrayElements(buf, srcBuf, 0);
srcImg.release();
grayImage.release();
return result;
}
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_blurGaussian
(JNIEnv *env, jclass, jintArray buf, jint w, jint h) {
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if(srcBuf == NULL) {
return 0;
}
Mat srcImg(h, w, CV_8UC4, (unsigned char *) srcBuf);
/**
* 高斯滤波
* 第一个参数:传入的图片
* 第二个参数:传出的图片
* 第三个参数:核心(必须是正数和奇数)
* 第四个参数:sigmaX代表高斯函数在x方向的标准偏差
* 第五个参数:sigmaY代表高斯函数在Y方向的标准偏差,有默认值为0
* 第六个参数:边界模式,使用默认值BORDER_DEFAULT
*/
GaussianBlur(srcImg, srcImg, Size(51, 51), 20, 20);
cvtColor(srcImg, srcImg, COLOR_RGBA2GRAY, 4);
int size = w * h;
//因为new出来的空间还在c中,java是不能直接使用的。
jintArray result = env->NewIntArray(size);
//将C的数组拷贝给java中的数组
env->SetIntArrayRegion(result, 0, size, srcBuf);
//释放c数组资源
env->ReleaseIntArrayElements(buf, srcBuf, 0);
return result;
}
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_blurBoxFilter
(JNIEnv *env, jclass, jintArray buf, jint w, jint h) {
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if(srcBuf == NULL) {
return 0;
}
Mat srcImg(h, w, CV_8UC4, (unsigned char *) srcBuf);
/**
* opencv中方框滤波函数
* 第一个参数:输入的图片
* 第二个参数:输出的图片
* 第三个参数:图片的深度(存储每个像素所用的位数)一般情况使用-1也就是原有的图像深度
* 第四个参数:核心的大小
* 第五个参数:锚点的位置,就是我们要进行处理的点,默认值(-1,-1)表示锚点在核的中心
* 第六个参数:normalize默认值为true,表示内核是否被其区域归一化(normalized)了,当normalize=true的时候,方框滤波就变成了我们熟悉的均值滤波。也就是说,
* 均值滤波是方框滤波归一化(normalized)后的特殊情况。其中,归一化就是把要处理的量都缩放到一个范围内,比如(0,1),以便统一处理和直观量化。
* 而非归一化(Unnormalized)的方框滤波用于计算每个像素邻域内的积分特性,比如密集光流算法(dense optical flow algorithms)
* 中用到的图像倒数的协方差矩阵(covariance matrices of image derivatives)如果我们要在可变的窗口中计算像素总和,可以使用integral()函数
* 第七个参数:边界模式,默认值BORDER_DEFAULT
*/
//使用这个方法,和均值滤波效果一样
boxFilter(srcImg, srcImg, -1, Size(20, 20));
cvtColor(srcImg, srcImg, COLOR_RGBA2GRAY, 4);
int size = w * h;
//因为new出来的空间还在c中,java是不能直接使用的。
jintArray result = env->NewIntArray(size);
//将C的数组拷贝给java中的数组
env->SetIntArrayRegion(result, 0, size, srcBuf);
//释放c数组资源
env->ReleaseIntArrayElements(buf, srcBuf, 0);
return result;
}
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_blurMean
(JNIEnv *env, jclass, jintArray buf, jint w, jint h) {
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if(srcBuf == NULL) {
return 0;
}
Mat srcImg(h, w, CV_8UC4, (unsigned char *) srcBuf);
/**
* 均值滤波(归一化之后又进行了方框滤波)
* 第一个参数:输入的图片
* 第二个参数:输出的图片
* 第三个参数:核心的大小
* 第四个参数:锚点的位置,就是我们要进行处理的点,默认值(-1,-1)表示锚点在核的中心
* 第五个参数:边界模式,默认值BORDER_DEFAULT
*/
blur(srcImg, srcImg, Size(30, 30));
cvtColor(srcImg, srcImg, COLOR_RGBA2GRAY, 4);
int size = w * h;
//因为new出来的空间还在c中,java是不能直接使用的。
jintArray result = env->NewIntArray(size);
//将C的数组拷贝给java中的数组
env->SetIntArrayRegion(result, 0, size, srcBuf);
//释放c数组资源
env->ReleaseIntArrayElements(buf, srcBuf, 0);
return result;
}
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_blurMedian
(JNIEnv *env, jclass, jintArray buf, jint w, jint h) {
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if(srcBuf == NULL) {
return 0;
}
Mat srcImg(h, w, CV_8UC4, (unsigned char *) srcBuf);
/**
* 中值滤波,孔径范围内的所有像素进行排序,然后取中位数,赋值给核心。
* 第一个参数:传入的图片
* 第二个参数:传出的图片
* 第三个参数:孔径的线性尺寸,必须是大于1的奇数
*/
medianBlur(srcImg,srcImg,31);
cvtColor(srcImg, srcImg, COLOR_RGBA2GRAY, 4);
int size = w * h;
//因为new出来的空间还在c中,java是不能直接使用的。
jintArray result = env->NewIntArray(size);
//将C的数组拷贝给java中的数组
env->SetIntArrayRegion(result, 0, size, srcBuf);
//释放c数组资源
env->ReleaseIntArrayElements(buf, srcBuf, 0);
return result;
}
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_blurBilateralFilter
(JNIEnv *env, jclass, jintArray buf, jint w, jint h) {
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if(srcBuf == NULL) {
return 0;
}
Mat srcImg(h, w, CV_8UC4, (unsigned char *) srcBuf);
cvtColor(srcImg, srcImg, COLOR_RGBA2RGB);
/**
* 双边滤波
* 第一个参数:传入的图片(必须是CV_8UC1或者CV_8UC3)
* 第二个参数:传出的图片
* 第三个参数:每个像素领域的直径
* 第四个参数:sigmaColor,这个值越大,该像素领域内会有更广的颜色被混合到一起
* 第五个参数:sigmaSpace,这个值越大,越远的像素会互相影响,第三个参数大于0时,领域的大小和这个值无关,否则成正比
* 第六个参数:使用默认值BORDER_DEFAULT
*/
bilateralFilter(srcImg, srcImg, 30, 50, 20);
cvtColor(srcImg, srcImg, COLOR_RGBA2GRAY, 4);
int size = w * h;
//因为new出来的空间还在c中,java是不能直接使用的。
jintArray result = env->NewIntArray(size);
//将C的数组拷贝给java中的数组
env->SetIntArrayRegion(result, 0, size, srcBuf);
//释放c数组资源
env->ReleaseIntArrayElements(buf, srcBuf, 0);
return result;
}
extern "C" JNIEXPORT jintArray JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_blur2(JNIEnv *env, jclass clazz, jintArray buf, jint w, jint h) {
// 获得图片矩阵数组指针
jint *srcBuf = env->GetIntArrayElements(buf, JNI_FALSE);
if (srcBuf == nullptr) {
return 0;
}
// 根据指针创建一个Mat 四个颜色通道
Mat imgData(h, w, CV_8UC4, (unsigned char *) srcBuf);
//变量定义
Mat src_gray, dst, abs_dst;
//使用高斯滤波消除噪声
GaussianBlur(imgData, imgData, Size(3, 3), 0, 0, BORDER_DEFAULT);
//转换为灰度图
cvtColor(imgData, src_gray, COLOR_RGBA2GRAY);
//使用Laplace函数
Laplacian(src_gray, dst, CV_16S, 3, 1, 0, BORDER_DEFAULT);
//计算绝对值
convertScaleAbs(dst, abs_dst);
// 恢复格式
//cvtColor(abs_dst, imgData, COLOR_GRAY2BGRA);
Mat dstResult;
//将dstImage内所有元素为0
dstResult = Scalar::all(0);
//使用Laplacian算子输出的边缘图,abs_dst作为掩码,来将原图imgData拷贝到目标图dstResult中
imgData.copyTo(dstResult, abs_dst);
int size = w * h;
jint *re = (jint *) dstResult.data;
jintArray result = env->NewIntArray(size);
env->SetIntArrayRegion(result, 0, size, re);
env->ReleaseIntArrayElements(buf, srcBuf, 0);
return result;
}
extern "C" JNIEXPORT jint JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_faceDetector(JNIEnv *env, jclass clazz, jobject bitmap,
jobject argb8888, jstring _path) {
const char *path = env->GetStringUTFChars(_path, 0);//文件路径
FaceDetector::loadCascade(path);//加载文件
Mat srcMat;//图片源矩阵
srcMat = BitmapMatUtil::bitmapToMat(env, bitmap);//图片源矩阵初始化
auto faces = FaceDetector::detectorFace(srcMat);//识别图片源矩阵,返回矩形集
for (Rect faceRect : faces) {// 在人脸部分画矩形
rectangle(srcMat, faceRect, Scalar(0, 253, 255), 5);//在srcMat上画矩形
BitmapMatUtil::matToBitmap(env, srcMat, bitmap);// 把mat放回bitmap中
}
env->ReleaseStringUTFChars(_path, path);//释放指针
return faces.size();//返回尺寸
}
extern "C" JNIEXPORT jobject JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_faceDetectorResize(JNIEnv *env, jclass clazz,
jobject bitmap, jobject argb8888,
jstring path_, jint width, jint height) {
const char *path = env->GetStringUTFChars(path_, 0);//文件路径
FaceDetector::loadCascade(path);//加载文件
Mat srcMat;//图片源矩阵
srcMat = BitmapMatUtil::bitmapToMat(env, bitmap);//图片源矩阵初始化
auto faces = FaceDetector::detectorFace(srcMat);//识别图片源矩阵,返回矩形集
Rect faceRect = faces[0];
rectangle(srcMat, faceRect, Scalar(0, 253, 255), 5);//在srcMat上画矩形
//识别目标区域区域---------------------------
Rect zone;
int w = faceRect.width;//宽
int h = faceRect.height;//高
int offSetLeft = w / 4;//x偏移
int offSetTop = static_cast<int>(h * 0.5);
zone.x = faceRect.x - offSetLeft;
zone.y = faceRect.y - offSetTop;
zone.width = w / 4 * 2 + w;
zone.height = static_cast<int>(zone.width * (height * 1.0 / width));
rectangle(srcMat, zone, Scalar(253, 95, 47), 5);//在srcMat上画矩形
env->ReleaseStringUTFChars(path_, path);//释放指针
resize(srcMat(zone), srcMat, Size(width, height));//<----重定义尺寸
return BitmapMatUtil::createBitmap(env, srcMat, argb8888);//返回图片
}
extern "C"
JNIEXPORT jobject JNICALL
Java_com_tianshaokai_opencv_OpenCVLearn_getIdCardNumber(JNIEnv *env, jclass clazz, jobject bitmap, jobject argb8888) {
Mat srcImage = BitmapMatUtil::bitmapToMat(env, bitmap);
Size fix_size = Size(640, 400);
resize(srcImage, srcImage, fix_size);
LOGD("Bitmap 已经成功转换为 Mat, 开始处理图片");
//灰度化 灰度化处理:图片灰度化处理就是将指定图片每个像素点的RGB三个分量通过一定的算法计算出该像素点的灰度值,使图像只含亮度而不含色彩信息。
Mat dstGray;
cvtColor(srcImage, dstGray, COLOR_BGR2GRAY);
//二值化 二值化:二值化处理就是将经过灰度化处理的图片转换为只包含黑色和白色两种颜色的图像,他们之间没有其他灰度的变化。在二值图中用255便是白色,0表示黑色。
threshold(dstGray, dstGray, 100, 255, THRESH_BINARY);
//返回指定形状和尺寸的结构元素
Mat erodeElement = getStructuringElement(MORPH_RECT, Size(20, 10));
//腐蚀:减少高亮部分 腐蚀:图片的腐蚀就是将得到的二值图中的黑色块进行放大。即连接图片中相邻黑色像素点的元素。通过腐蚀可以把身份证上的身份证号码连接在一起形成一个矩形区域。
erode(dstGray, dstGray, erodeElement);
//膨胀:增加高亮部分
// dilate(dstGray, dstGray, erodeElement);
//轮廓检测 轮廊检测:图片经过腐蚀操作后相邻点会连接在一起形成一个大的区域,这个时候通过轮廊检测就可以把每个大的区域找出来,这样就可以定位到身份证上面号码的区域。
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(dstGray, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
Mat result;
for (int i = 0; i < hierarchy.size(); i++) {
Rect rect = boundingRect(contours.at(i));
rectangle(srcImage, rect, Scalar(255, 0, 255));
// 定义身份证号位置大于图片的一半,并且宽度是高度的6倍以上
if (rect.y > srcImage.rows / 2 && rect.width / rect.height > 6) {
result = srcImage(rect);
break;
}
}
LOGD("图片处理成功,开始返回身份证号图片");
jobject jobBitmap = BitmapMatUtil::createBitmap(env, result, argb8888);
result.release();
dstGray.release();
srcImage.release();
return jobBitmap;
}
|
1754a8b60afdf47372f7e0bd66026b1d53076d09
|
5218777f96dad9adb655c738ac171369c4ae243a
|
/ExamPrep2/TopView/TopView.h
|
c6324c17cd1f58eb0199c9952d350a9547917e37
|
[] |
no_license
|
Pavel-Romanov99/Data-Structures-and-Programming
|
ddb234ac2146f903abf1b1a837ab79a50198d6d8
|
8d0ac679e717ff5f0cecf14f69b6a5b9f0a7f2c5
|
refs/heads/master
| 2022-04-02T06:28:39.155165
| 2020-01-17T09:54:48
| 2020-01-17T09:54:48
| 212,769,727
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 2,031
|
h
|
TopView.h
|
#pragma once
#include <iostream>
#include <map>
#include <queue>
#include <iterator>
using namespace std;
struct node
{
int data;
node* left;
node* right;
int key;
bool visited = 0;
};
node* getNewNode(int data){
node* temp = new node();
temp->data = data;
temp->left = NULL;
temp->right = NULL;
return temp;
}
class BinaryTree {
public:
node* root;
BinaryTree() {
this->root = NULL;
this->root->key = 0;
}
BinaryTree(int data) {
root = getNewNode(data);
}
node* insertNode(node* root, int data) {
if (root == NULL) {
root = getNewNode(data);
}
else if (data <= root->data) {
root->left = insertNode(root->left, data);
}
else if (data > root->data) {
root->right = insertNode(root->right, data);
}
return root;
}
void InOrder(node* root) {
if (root == NULL) return;
InOrder(root->left);
cout << root->data << " ";
InOrder(root->right);
}
void Levels(node* root) {
if (root == NULL) return;
if (root->left != NULL)
{
root->left->key = -1 + root->key;
}
if (root->right != NULL)
{
root->right->key = root->key + 1;
}
cout << "(" << root->data << " " << root->key << ") ";
Levels(root->left);
Levels(root->right);
}
void TopView(node* root) {
queue<node*> queue;
map<int, int> map1;
queue.push(root);
while (!queue.empty()) {
node* current = queue.front();
queue.pop();
if (map1.find(current->key) == map1.end()) { //cannot find the elem
map1.insert(std::pair<int, int> (current->key, current->data));
}
if (current->left != NULL) {
queue.push(current->left);
}
if (current->right != NULL) {
queue.push(current->right);
}
}
map<int, int>::iterator itr;
for (itr = map1.begin(); itr != map1.end(); ++itr) {
cout << itr->second << " ";
}
}
int getHeight(node* root) {
if (root == NULL) return 0;
return 1 + max(getHeight(root->left), getHeight(root->right));
}
};
|
56ecf96b2b0d6ae1a776caef268dee8553a9c297
|
1d28a48f1e02f81a8abf5a33c233d9c38e339213
|
/SVEngine/src/basesys/SVPickProcess.cpp
|
ff31e754840a588c765c2b2b2682e19783d41e46
|
[
"MIT"
] |
permissive
|
SVEChina/SVEngine
|
4972bed081b858c39e5871c43fd39e80c527c2b1
|
56174f479a3096e57165448142c1822e7db8c02f
|
refs/heads/master
| 2021-07-09T10:07:46.350906
| 2020-05-24T04:10:57
| 2020-05-24T04:10:57
| 150,706,405
| 34
| 9
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 12,121
|
cpp
|
SVPickProcess.cpp
|
//
// SVPickProcess.h
// SVEngine
// Copyright 2017-2020
// yizhou Fu,long Yin,longfei Lin,ziyu Xu,xiaofan Li,daming Li
//
#include "SVPickProcess.h"
#include "../app/SVInst.h"
#include "../app/SVGlobalMgr.h"
#include "../event/SVEventMgr.h"
#include "../event/SVOpEvent.h"
#include "../basesys/SVSceneMgr.h"
#include "../basesys/SVCameraMgr.h"
#include "../node/SVScene.h"
#include "../node/SVCameraNode.h"
#include "../ui/SVUIMgr.h"
//获取射线求教节点
SVVisitRayPick::SVVisitRayPick(FVec3& _rayStart,FVec3& _rayEnd)
:m_rayStart(_rayStart)
,m_rayEnd(_rayEnd){
}
SVVisitRayPick::~SVVisitRayPick() {
m_nodearray.destroy();
}
bool SVVisitRayPick::visit(SVNodePtr _node) {
if(_node->getvisible() && _node->getcanSelect() ){
SVBoundBox t_box_sw = _node->getAABBSW();
if( t_box_sw.getIntersectionValid(m_rayStart, m_rayEnd) ){
m_nodearray.append(_node);
}
}
return true;
}
SVNodePtr SVVisitRayPick::getCrossNode(FVec3& _campos){
SVNodePtr t_node = nullptr;
f32 t_dis = 1000000;
for(s32 i=0;i<m_nodearray.size();i++){
if (m_nodearray[i]->getcanSelect() == false) {
continue;
}
FVec3 tt = _campos - m_nodearray[i]->getPosition();
f32 t_cam_dis = tt.length();
if( t_cam_dis<t_dis){
t_dis = t_cam_dis;
t_node = m_nodearray[i];
}
}
return t_node;
}
//
//获取射线求教节点
SVVisitRayPickUI::SVVisitRayPickUI(FVec3& _rayStart,FVec3& _rayEnd)
:SVVisitRayPick(_rayStart,_rayEnd)
,m_pNode(nullptr){
}
SVVisitRayPickUI::~SVVisitRayPickUI() {
m_pNode = nullptr;
}
bool SVVisitRayPickUI::visit(SVNodePtr _node) {
if(_node->getvisible() && _node->getcanSelect() ){
SVBoundBox t_box_sw = _node->getAABBSW();
if( t_box_sw.getIntersectionValid(m_rayStart, m_rayEnd)){
m_pNode = _node;
return true;
}
}
return false;
}
SVNodePtr SVVisitRayPickUI::getPickNode() {
return m_pNode;
}
//
SVPickProcess::SVPickProcess(SVInst *_app)
:SVProcess(_app) {
m_enablePick = false;
m_curPickNode = nullptr;
m_curPickUI = nullptr;
}
SVPickProcess::~SVPickProcess() {
m_curPickNode = nullptr;
m_curPickUI = nullptr;
}
void SVPickProcess::enablePick() {
m_enablePick = true;
}
void SVPickProcess::disablePick() {
clear();
m_enablePick = false;
}
void SVPickProcess::clear() {
m_curPickNode = nullptr;
m_curPickUI = nullptr;
}
//
SVNodePtr SVPickProcess::getPickNode(){
return m_curPickNode;
}
SVNodePtr SVPickProcess::getPickUI(){
return m_curPickUI;
}
//获取射线
bool SVPickProcess::_getRay(SVCameraNodePtr _cam,s32 _sx,s32 _sy,FVec3& _rayStart,FVec3& _rayEnd){
if( _cam){
f32 m_screenW = mApp->m_pGlobalParam->m_inner_width;
f32 m_screenH = mApp->m_pGlobalParam->m_inner_height;
//投影坐标x(-1,1.0),y(-1,1.0)
FVec4 t_proj_v_begin = FVec4((_sx/m_screenW - 0.5f)*2.0f,(_sy/m_screenH - 0.5f)*2.0f,-1.0f,1.0f);
FVec4 t_proj_v_end = FVec4((_sx/m_screenW - 0.5f)*2.0f,(_sy/m_screenH - 0.5f)*2.0f,1.0f,1.0f);
FMat4 t_vp_inv = inverse(_cam->getVPMatObj());
FVec4 t_world_begin = t_vp_inv*t_proj_v_begin;
FVec4 t_world_end = t_vp_inv*t_proj_v_end;
t_world_begin = t_world_begin/t_world_begin.w;
t_world_end = t_world_end/t_world_end.w;
//射线(确认过的 没错了)
_rayStart.x = t_world_begin.x;
_rayStart.y = t_world_begin.y;
_rayStart.z = t_world_begin.z;
_rayEnd.x = t_world_end.x;
_rayEnd.y = t_world_end.y;
_rayEnd.z = t_world_end.z;
return true;
}
return false;
}
bool SVPickProcess::_getRayMat(SVCameraNodePtr _cam,FMat4 _vpMat,s32 _sx,s32 _sy,FVec3& _rayStart,FVec3& _rayEnd){
if( _cam){
f32 m_screenW = mApp->m_pGlobalParam->m_inner_width;
f32 m_screenH = mApp->m_pGlobalParam->m_inner_height;
//投影坐标x(-1,1.0),y(-1,1.0)
FVec4 t_proj_v_begin = FVec4((_sx/m_screenW - 0.5f)*2.0f,(_sy/m_screenH - 0.5f)*2.0f,-1.0f,1.0f);
FVec4 t_proj_v_end = FVec4((_sx/m_screenW - 0.5f)*2.0f,(_sy/m_screenH - 0.5f)*2.0f,1.0f,1.0f);
FMat4 t_vp_inv = inverse(_vpMat);
FVec4 t_world_begin = t_vp_inv*t_proj_v_begin;
FVec4 t_world_end = t_vp_inv*t_proj_v_end;
t_world_begin = t_world_begin/t_world_begin.w;
t_world_end = t_world_end/t_world_end.w;
//射线(确认过的 没错了)
_rayStart.x = t_world_begin.x;
_rayStart.y = t_world_begin.y;
_rayStart.z = t_world_begin.z;
_rayEnd.x = t_world_end.x;
_rayEnd.y = t_world_end.y;
_rayEnd.z = t_world_end.z;
return true;
}
return false;
}
//屏幕坐标(左上角为 0,0),(720,1280)
bool SVPickProcess::pickScene(SVCameraNodePtr _cam,s32 _sx,s32 _sy){
SVScenePtr t_sc = mApp->getSceneMgr()->getScene();
if (_cam && t_sc) {
FVec3 t_start,t_end;
if( _getRayMat(_cam,_cam->getVPMatObj(),_sx,_sy,t_start,t_end) ){
//射线求交
SVVisitRayPickPtr t_visit = MakeSharedPtr<SVVisitRayPick>(t_start,t_end);
t_sc->visit(t_visit);
FVec3 t_pos = _cam->getPosition();
SVNodePtr t_node = t_visit->getCrossNode(t_pos);
if(t_node){
_pick(t_node);
return true;
}else{
SVPickGetNothingEventPtr t_event = MakeSharedPtr<SVPickGetNothingEvent>();
t_event->m_px = _sx;
t_event->m_py = _sy;
mApp->getEventMgr()->pushEvent(t_event);
}
}
}
return false;
}
//相机和屏幕坐标(都是以左下角为(0,0))
bool SVPickProcess::pickUI(s32 _sx,s32 _sy){
SVCameraNodePtr t_ui_cam = mApp->getCameraMgr()->getUICamera();
FVec3 t_start,t_end;
t_start.set(_sx, _sy, -10000.0f);
t_end.set(_sx, _sy, 10000.0f);
//构建射线
SVVisitRayPickUIPtr t_visit = MakeSharedPtr<SVVisitRayPickUI>(t_start,t_end);
mApp->getUIMgr()->visit(t_visit);
SVNodePtr t_pNode = t_visit->getPickNode();
if(t_pNode){
_pickUI(t_pNode);
return true;
}else{
SVPickGetNothingEventPtr t_event = MakeSharedPtr<SVPickGetNothingEvent>();
t_event->m_px = _sx;
t_event->m_py = _sy;
mApp->getEventMgr()->pushEvent(t_event);
}
return false;
}
//移动节点
void SVPickProcess::moveNode(SVCameraNodePtr _cam,s32 _sx,s32 _sy){
if (_cam) {
FVec3 t_start,t_end;
if( m_curPickNode && _getRay(_cam,_sx,_sy,t_start,t_end) ){
// //构建移动平面(这个平面可以绘制出来)
// FVec3 t_pos = m_curPickNode->getPosition();
// FVec3 t_nor = _cam->getDirection();
// plane3df t_plane(t_pos,t_nor);
// //获取与平面的交点
// FVec3 t_out_cross_pt;
// if( t_plane.getIntersectionWithLine(t_ray.start, t_ray.getVector().normalize(), t_out_cross_pt) ){
// m_curPickNode->setPosition(t_out_cross_pt);
// }
}
}
}
bool SVPickProcess::getCrossPoint(SVCameraNodePtr _cam,s32 _sx,s32 _sy,FVec3& _crosspt){
FVec3 t_start,t_end;
if( _getRay(_cam,_sx,_sy,t_start,t_end) ){
//构建移动平面(这个平面可以绘制出来)
FVec3 t_pos = t_start;
FVec3 t_dir = t_end - t_start;
FVec4 t_plane = FVec4(0.0f,0.0f,1.0f,0.0f);
//
s32 t_ret = rayPlaneIntersection(_crosspt,t_pos,t_dir,t_plane);
if(t_ret>0)
return true;
}
return false;
}
bool SVPickProcess::getCrossPointWithPlane(SVCameraNodePtr _cam,s32 _sx,s32 _sy,FVec3& _crosspt, FVec4& _plane){
FVec3 t_start,t_end;
if( _getRay(_cam,_sx,_sy,t_start,t_end) ){
//构建移动平面(这个平面可以绘制出来)
FVec3 t_pos = t_start;
FVec3 t_dir = t_end - t_start;
//
s32 t_ret = rayPlaneIntersection(_crosspt,t_pos,t_dir,_plane);
if(t_ret>0)
return true;
}
return false;
}
bool SVPickProcess::getCrossPointUI(SVCameraNodePtr _cam,s32 _sx,s32 _sy,FVec3& _crosspt){
FVec3 t_start,t_end;
//error fyz
// if(_cam){
// if(_getRayMat(_cam,mApp->getCameraMgr()->getMainCamera()->getVPMatObjUI(),_sx,_sy,t_start,t_end)){
// //构建移动平面(这个平面可以绘制出来)
// FVec3 t_pos = t_start;
// FVec3 t_dir = t_end - t_start;
// FVec4 t_plane = FVec4(0.0f,0.0f,1.0f,0.0f);
// //
// s32 t_ret = rayPlaneIntersection(_crosspt,t_pos,t_dir,t_plane);
// if(t_ret>0)
// return true;
// }
// }
return false;
}
//
void SVPickProcess::_pick(SVNodePtr _node){
if (_node) {
if (m_curPickNode != _node) {
if(m_curPickNode){
m_curPickNode->setbeSelect(false);
SVPickLoseEventPtr t_event = MakeSharedPtr<SVPickLoseEvent>(m_curPickNode);
mApp->getEventMgr()->pushEvent(t_event);
}
m_curPickNode = _node;
SVPickChangeEventPtr t_event = MakeSharedPtr<SVPickChangeEvent>(m_curPickNode,_node);
mApp->getEventMgr()->pushEvent(t_event);
}
_node->setbeSelect(true);
SVPickGetEventPtr t_event = MakeSharedPtr<SVPickGetEvent>(_node);
mApp->getEventMgr()->pushEvent(t_event);
}
}
void SVPickProcess::_pickUI(SVNodePtr _node){
if (_node) {
if (m_curPickUI != _node) {
if(m_curPickUI){
m_curPickUI->setbeSelect(false);
// SVPickLoseEventPtr t_event = MakeSharedPtr<SVPickLoseEvent>(m_curPickUI);
// mApp->getEventMgr()->pushEvent(t_event);
}
m_curPickUI = _node;
// SVPickChangeEventPtr t_event = MakeSharedPtr<SVPickChangeEvent>(m_curPickUI,_node);
// mApp->getEventMgr()->pushEvent(t_event);
}
_node->setbeSelect(true);
SVPickGetUIEventPtr t_event = MakeSharedPtr<SVPickGetUIEvent>(_node);
mApp->getEventMgr()->pushEvent(t_event);
}
}
bool SVPickProcess::procEvent(SVEventPtr _event){
SVCameraNodePtr t_camera = mApp->m_pGlobalMgr->m_pCameraMgr->getMainCamera();
if(_event->eventType == EVN_T_TOUCH_BEGIN){
SVTouchEventPtr t_touch = DYN_TO_SHAREPTR(SVTouchEvent,_event);
f32 t_mod_x = t_touch->x;
f32 t_mod_y = t_touch->y;
pickScene(t_camera,t_mod_x,t_mod_y);
pickUI(t_mod_x,t_mod_y);
}else if(_event->eventType == EVN_T_TOUCH_END){
SVTouchEventPtr t_touch = DYN_TO_SHAREPTR(SVTouchEvent,_event);
f32 t_mod_x = t_touch->x;
f32 t_mod_y = t_touch->y;
}else if(_event->eventType == EVN_T_TOUCH_MOVE){
SVTouchEventPtr t_touch = DYN_TO_SHAREPTR(SVTouchEvent,_event);
f32 t_mod_x = t_touch->x;
f32 t_mod_y = t_touch->y;
moveNode(t_camera,t_mod_x,t_mod_y);
}
return true;
}
void SVPickProcess::transScreenPtToWorld(FVec2 &_screenPt, FVec3 &_worldPt){
SVCameraNodePtr t_camera = mApp->getCameraMgr()->getMainCamera();
FMat4 t_cameraMatrix = t_camera->getViewMatObj();
FVec3 t_cameraEye = t_camera->getPosition();
//构建虚拟平面
FVec3 t_cameraDir = FVec3(-t_cameraMatrix[2],
-t_cameraMatrix[6],
-t_cameraMatrix[10]);
t_cameraDir.normalize();
FVec3 t_targetPos = t_cameraEye + t_cameraDir*0.0001f;
t_targetPos.normalize();
f32 t_dis = dot(t_targetPos,t_cameraDir);
FVec4 t_plane = FVec4(-t_cameraDir,t_dis);
//求交点
FVec3 t_pos;
f32 t_pt_x = _screenPt.x;
f32 t_pt_y = _screenPt.y;
f32 t_pt_z = 0.0f;
if(getCrossPointWithPlane(t_camera,t_pt_x, t_pt_y,t_pos, t_plane) ){
t_pt_x = t_pos.x;
t_pt_y = t_pos.y;
t_pt_z = t_pos.z;
}
_worldPt.set(t_pt_x, t_pt_y, t_pt_z);
}
|
15fb17913edba69a83849c0e18f58167a2b76095
|
971713859cee54860e32dce538a7d5e796487c68
|
/unisim/unisim_lib/unisim/component/tlm2/chipset/attic/arm926ejs_pxp/vic/vic.hh
|
91494bf07121c50628603f48af1208c3e8b9a770
|
[] |
no_license
|
binsec/cav2021-artifacts
|
3d790f1e067d1ca9c4123010e3af522b85703e54
|
ab9e387122968f827f7d4df696c2ca3d56229594
|
refs/heads/main
| 2023-04-15T17:10:10.228821
| 2021-04-26T15:10:20
| 2021-04-26T15:10:20
| 361,684,640
| 2
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 11,684
|
hh
|
vic.hh
|
/*
* Copyright (c) 2010,
* Commissariat a l'Energie Atomique (CEA)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of CEA nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Daniel Gracia Perez (daniel.gracia-perez@cea.fr)
*/
#ifndef __UNISIM_COMPONENT_TLM2_CHIPSET_ARM926EJS_PXP_VIC_VIC_HH__
#define __UNISIM_COMPONENT_TLM2_CHIPSET_ARM926EJS_PXP_VIC_VIC_HH__
#include <systemc>
#include <tlm>
#include <tlm_utils/passthrough_target_socket.h>
#include <inttypes.h>
#include "unisim/kernel/kernel.hh"
#include "unisim/kernel/logger/logger.hh"
#include "unisim/component/tlm2/chipset/arm926ejs_pxp/vic/vic_int_source_identifier.hh"
#include "unisim/util/generic_peripheral_register/generic_peripheral_register.hh"
namespace unisim {
namespace component {
namespace tlm2 {
namespace chipset {
namespace arm926ejs_pxp {
namespace vic {
class VIC
: public unisim::kernel::Object
, public sc_module
, public VICIntSourceIdentifierInterface
, public unisim::util::generic_peripheral_register::GenericPeripheralRegisterInterface<uint32_t>
{
private:
/** total number of incomming interrupts */
static const unsigned int NUM_SOURCE_INT = 32;
/** total number of vectored interrupts */
static const unsigned int NUM_VECT_INT = 16;
public:
typedef tlm::tlm_base_protocol_types::tlm_payload_type transaction_type;
typedef tlm::tlm_base_protocol_types::tlm_phase_type phase_type;
typedef tlm::tlm_sync_enum sync_enum_type;
sc_core::sc_in<bool> *vicintsource[NUM_SOURCE_INT];
sc_core::sc_in<bool> nvicfiqin;
sc_core::sc_in<bool> nvicirqin;
sc_core::sc_in<uint32_t> vicvectaddrin;
sc_core::sc_out<bool> nvicfiq;
sc_core::sc_out<bool> nvicirq;
sc_core::sc_out<uint32_t> vicvectaddrout;
/** Target socket for the bus connection */
tlm_utils::passthrough_target_socket<VIC, 32>
bus_target_socket;
SC_HAS_PROCESS(VIC);
VIC(const sc_module_name &name, Object *parent = 0);
~VIC();
virtual bool BeginSetup();
private:
/** Semaphore to ensure that only one process is modifying the VIC state
*/
sc_core::sc_semaphore state_semaphore;
/** event that handles the update process of the VIC
*/
sc_core::sc_event update_status_event;
/** Status update thread handler
* Basically it just waits for update status events and updates the status of
* the VIC depending on all the possible entries by calling the UpdateStatus
* method.
*/
void UpdateStatusHandler();
/** Update the status of the VIC depending on all the possible entries
*/
void UpdateStatus();
/** Is the VIC forwarding the nvicirqin?
*
* This variable inform just of the VIC status, it is only used for verbose
* requirements.
*/
bool forwarding_nvicirqin;
/** Previous nvicirqin value
*
* This variable informs just of the VIC status, it is only used for verbose
* requirements.
*/
bool nvicirqin_value;
/** Indicates if a vectored interrupt is being serviced and if so the
* nesting level
*/
unsigned int vect_int_serviced;
/** If vect_int_serviced is true then this indicates the priority level
*/
uint32_t vect_int_serviced_level[NUM_VECT_INT];
/** Indicates if an interrupt is ready for vectored service
*/
bool vect_int_for_service;
/** Level that would be serviced if requested
*/
unsigned int max_vect_int_for_service;
/** Registers storage */
uint8_t regs[0x01000UL];
/** Value of the source identifier */
uint32_t int_source;
/** Source interrupt handling */
virtual void VICIntSourceReceived(int id, bool value);
/** Source identifiers methods */
VICIntSourceIdentifier *source_identifier_method[NUM_SOURCE_INT];
/** value of the nVICFIQ */
bool nvicfiq_value;
/** value of the nVICIRQ */
bool nvicirq_value;
/** value of the VICVECTADDROUT */
uint32_t vicvectaddrout_value;
/**************************************************************************/
/* Virtual methods for the target socket for the bus connection START */
/**************************************************************************/
sync_enum_type bus_target_nb_transport_fw(transaction_type &trans,
phase_type &phase,
sc_core::sc_time &time);
void bus_target_b_transport(transaction_type &trans,
sc_core::sc_time &delay);
bool bus_target_get_direct_mem_ptr(transaction_type &trans,
tlm::tlm_dmi &dmi_data);
unsigned int bus_target_transport_dbg(transaction_type &trans);
/**************************************************************************/
/* Virtual methods for the target socket for the bus connection END */
/**************************************************************************/
/**************************************************************************/
/* Methods to get and set the registers START */
/**************************************************************************/
static const uint32_t VICIRQSTATUSAddr = 0x0000UL;
static const uint32_t VICFIQSTATUSAddr = 0x0004UL;
static const uint32_t VICRAWINTRAddr = 0x0008UL;
static const uint32_t VICINTSELECTAddr = 0x000cUL;
static const uint32_t VICINTENABLEAddr = 0x0010UL;
static const uint32_t VICINTENCLEARAddr = 0x0014UL;
static const uint32_t VICSOFTINTAddr = 0x0018UL;
static const uint32_t VICSOFTINTCLEARAddr = 0x001cUL;
static const uint32_t VICPROTECTIONAddr = 0x0020UL;
static const uint32_t VICVECTADDRAddr = 0x0030UL;
static const uint32_t VICDEFVECTADDRAddr = 0x0034UL;
static const uint32_t VICVECTADDRBaseAddr = 0x0100UL;
static const uint32_t VICVECTCNTLBaseAddr = 0x0200UL;
static const uint32_t VICPERIPHIDBaseAddr = 0x0fe0UL;
static const uint32_t VICPCELLIDBaseAddr = 0x0ff0UL;
static const uint32_t VICITCRAddr = 0x0300UL;
static const uint32_t VICITIP1Addr = 0x0304UL;
static const uint32_t VICITIP2Addr = 0x0308UL;
static const uint32_t VICITOP1Addr = 0x030cUL;
static const uint32_t VICITOP2Addr = 0x0310UL;
static const uint32_t NUMREGS = 55; // Note: Test registers are not available
static const uint32_t REGS_ADDR_ARRAY[NUMREGS];
static const char *REGS_NAME_ARRAY[NUMREGS];
/** Get interface for the generic peripheral register interface
*
* @param addr the address to consider
* @return the value of the register pointed by the address
*/
virtual uint32_t GetPeripheralRegister(uint64_t addr);
/** Set interface for the generic peripheral register interface
*
* @param addr the address to consider
* @param value the value to set the register to
*/
virtual void SetPeripheralRegister(uint64_t addr, uint32_t value);
/** Returns the enable field of the VICVECTCNTL register.
*
* @param value the register value
* @return true if enable is set, false otherwise
*/
bool VECTCNTLEnable(uint32_t value);
/** Returns the source field of the VICVECTCNTL register
*
* @param value the register value
* @return the value of the source field
*/
uint32_t VECTCNTLSource(uint32_t value);
/** Returns the register pointed by the given address
*
* @param addr the address to consider
* @return the value of the register pointed by the address
*/
uint32_t GetRegister(uint32_t addr) const;
/** Returns the register pointed by the given address plus index * 4
*
* @param addr the base address to consider
* @param index the register index from the base address
* @return the value of the register pointed by address + (index * 4)
*/
uint32_t GetRegister(uint32_t addr, uint32_t index) const;
/** Sets the register pointed by the given address
*
* @param addr the address to consider
* @param value the value to set the register
*/
void SetRegister(uint32_t addr, uint32_t value);
/**************************************************************************/
/* Methods to get and set the registers END */
/**************************************************************************/
/** Get the source field from the given vector control register value
*
* @param value the value of the vector control register
* @return the source field of the value
*/
uint32_t VECTCNTLSource(uint32_t value) const;
/** Get the enable field from the given vector control register value
*
* @param value the value of the vector control register
* @return the enable field of the value
*/
bool VECTCNTLEnable(uint32_t value) const;
/** Base address of the VIC */
uint32_t base_addr;
/** UNISIM Parameter for the base address of the VIC */
unisim::kernel::variable::Parameter<uint32_t> param_base_addr;
/** Register helpers to use the UNISIM Register service */
unisim::util::generic_peripheral_register::GenericPeripheralWordRegister *
regs_accessor[NUMREGS];
/** UNISIM Registers for the timer registers */
unisim::kernel::variable::Register<
unisim::util::generic_peripheral_register::GenericPeripheralWordRegister
> *
regs_service[NUMREGS];
/** Verbose */
uint32_t verbose;
/** UNISIM Paramter for verbose */
unisim::kernel::variable::Parameter<uint32_t> param_verbose;
/** Verbose levels */
static const uint32_t V0 = 0x01UL;
static const uint32_t V1 = 0x03UL;
static const uint32_t V2 = 0x07UL;
static const uint32_t V3 = 0x0fUL;
/** Verbose target mask */
static const uint32_t V_INIRQ = 0x01UL << 4;
static const uint32_t V_INFIQ = 0x01UL << 5;
static const uint32_t V_INVICIRQ = 0x01UL << 6;
static const uint32_t V_INVICFIQ = 0x01UL << 7;
static const uint32_t V_OUTIRQ = 0x01UL << 8;
static const uint32_t V_OUTFIQ = 0x01UL << 9;
static const uint32_t V_STATUS = 0x01UL << 12;
static const uint32_t V_TRANS = 0x01UL << 16;
/** Check if we should verbose */
bool VERBOSE(uint32_t level, uint32_t mask) const
{
uint32_t ok_level = level & verbose;
uint32_t ok_mask = (~verbose) & mask;
return ok_level && ok_mask;
};
/** Interface to the UNISIM logger */
unisim::kernel::logger::Logger logger;
};
} // end of namespace vic
} // end of namespace arm926ejs_pxp
} // end of namespace chipset
} // end of namespace tlm2
} // end of namespace component
} // end of namespace unisim
#endif // __UNISIM_COMPONENT_TLM2_CHIPSET_ARM926EJS_PXP_VIC_VIC_HH__
|
39031feae842490a718480b30aeb37379757d068
|
324b47d0434a5c829b1e0dfb8ba024f82c0092cf
|
/BullsCows.cpp
|
843bbe4a12bbfd123d876a540c76aa9b27b9b401
|
[] |
no_license
|
jolin1337/Bulls-Cows
|
ef76dfe0677e37af1dcdf4af181fbda071277209
|
1cebe183082cae49d03a8b7eb97dc7f2c4a5d2cf
|
refs/heads/master
| 2021-01-23T14:56:30.332407
| 2012-12-20T13:35:51
| 2012-12-20T13:35:51
| null | 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 16,276
|
cpp
|
BullsCows.cpp
|
#include "BullsCows.h"
#include "DistinktNumber/DistinktNumber.h"
#include "header.h"
using namespace std;
using SR::ScreenRender;
BullsCows::BullsCows():menues(&sr, &keys), solveres(&sr, &keys){
playing = true; // så länge spelet håller igång är denna true, så nu startas spelt
resultPos.X = 10; // tabellen börgar på X=10
resultPos.Y = sr.height-15; // Y = 100%-15rows
highscore.readFile("highscore.txt"); // initiera highscore listan
}
BullsCows::BullsCows(string file):menues(&sr, &keys), solveres(&sr, &keys){
playing = true; // så länge spelet håller igång är denna true, så nu startas spelt
resultPos.X = 10; // tabellen börgar på X=10
resultPos.Y = sr.height-15; // Y = 100%-15rows
highscore.readFile(file.c_str()); // initiera highscore listan
}
BullsCows::~BullsCows(){
highscore.saveFile(highscore.getFileName()); // spara tillbaks highscore listan när programmet avslutas
}
int BullsCows::start(){
while(playing){ // main-loop
int scores; // antal poäng för nuvarande spelare
string name; // namnet för nuvarande spelare
sr.clearScreen(); // ränsa skärmen
menues.logoEnd = logo(sr, sr.width/2-68/2, 2);// skriv ut loggan och skicka värdet till menyn så att den skrivs ut på rätt position
menues.printMenu(); // skriv ut menyrubrikerna
int opt = menues.menu(); // starta interaktion med användaren
switch(opt){ // vad har användaren valt?
case 0: // Start Think of
solveres.solve(); // starta minispelet solver
break;
case 1: // Start Guess of
creater(); // starta minispelet creater
break;
case 2: // Challange computer
scores = challangeComputer(); // starta utmaningen för datorn
// spara poängen från spelet i score
name = whatsYourName(sr, keys); // ta reda på namnet på den som spelat
if(name != "") // om namnet inte är tomt
highscore.addNew(name, scores); // spara spelaren
// spara spelaren, för säkerhetens skull
highscore.saveFile(highscore.getFileName());
case 3: // Instructions
docs(); // visa hur man spelar Bulls and Cows spelet
break;
case 4: // Hightscore
highscore.print(sr); // visa highscore listan i screenbuffern
sr.render(); // skriv ut highscore listan på skärment
while(keys.getch() != '\n'); // vänta på användaren trycker enter/retur tangenten
break;
case 5: // About
about(); // visa vem som är awsome och har programmerat detta program
break;
case 6: // Exit
playing = false; // stäng programmet
break;
default: // ett okänt returvärde från användaren....
docs(); // vi visar då docs
}
}
return 0;
}
void BullsCows::docs(){
sr.clearScreen(); // ränsa bufferten i ScreenRender och ränsa skärmen
int i=2; // deklarera i som definerar vilken rad som skall skrivas
// skriv ut förklarande text på vad spelet går ut på och vad det är för spel.
sr.printString(sr.width/2 - 44/2,0,"This is a guide to the game \"Bulls and cows\"", RED);
sr.printString(10, i++,"The Game consist of very simple rules. To guess the secret number.", BLACK);
sr.printString(10, i++,"Each part in this number is a distinkt number 0-9. You have 10 ", BLACK);
sr.printString(10, i++,"guesses to guess the number with no time limits.", BLACK);
i++;
sr.printString(10, i++,"There are 2 practice modes and one mode to challange the", BLACK);
sr.printString(10, i++,"computer(that consist of both practice modes). To challange", BLACK);
sr.printString(10, i++,"the computer you need to get as low scores as possible.", BLACK);
sr.printString(10, i++,"You get one score/guess and minus one score/computer guess.", BLACK);
i++;
sr.printString(12, i++,"Mode 1, Guess of:", BLUE);
sr.printString(12, i++,"In this mode you need to ", BLACK);
sr.printString(12, i++,"guess the number that the", BLACK);
sr.printString(12, i++,"computer generates", BLACK);
i -=4;
sr.printString(45, i++,"Mode 2, Think of:", BLUE);
sr.printString(45, i++,"In this mode you need to ", BLACK);
sr.printString(45, i++,"think of a number that the", BLACK);
sr.printString(45, i++,"computer will guess.", BLACK);
sr.printString(45, i++,"Then tell the computer ", BLACK);
sr.printString(45, i++,"how many bulls and cows ", BLACK);
sr.printString(45, i++,"the number got in it.", BLACK);
i++;
sr.printString(10, i++,"Example: ", GREEN);
sr.printString(10, i++,"The current number is 1342 and the guess is 3641.", BLACK);
sr.printString(10, i++,"Then the result/outputs are one bull and two cows.", BLACK);
sr.printString(10, i++,"And so on untill the number is guessed.", BLACK);
sr.render();
keys.getch();
}
void BullsCows::about(){
int x=1, // låt x och y definera vilken position som
y=1; // texten skall skrivas ut på.
sr.clearScreen();
sr.printString(x,y++," ____ __ ");
sr.printString(x,y++," | \\.-`` ) ");
sr.printString(x,y++," |---``\\ _.' ");
sr.printString(x,y++," .-`'---``_.' ");
sr.printString(x,y++," (___..--`` ");
y++; x += 25;
sr.printString(x,2,"Programmer/Designer of this game is", BLACK);
sr.printString(x,3," Johannes Linden.", RED);
sr.printString(x,4,"johannes.93.1337@gmail.com", BLUE);
sr.printString(x,5,"http://johannes.pastorn.nu/#Projects", GREEN);
sr.printString(x,y++,"This source code can be found on github:", BLACK);
sr.printString(x,y++,"https://github.com/jolin1337", GREEN);
sr.render(); // visa för användaren
keys.getch(); // vänta på vilken knappnedtryckning som helst
}
int BullsCows::challangeComputer(){
bool compsTurn = false, // avgör vem det är som skall gissa
whanaPlay = true; // avgör hur länge användaren vill spela
int scoreU = 0, // poängen för användaren
scoreC = 0, // poängen för datorn
turns = 0; // antal rundor som har körts
while(whanaPlay){ // så länge spelaren vill spela
sr.clearScreen(); // ränsa skärmen och bufferten i ScreenRender
// skriv ut poäng för spelarna
sr.printString(sr.width - 27, resultPos.Y, "Scores:", YELLOW);
sr.drawRect(sr.width - 28, resultPos.Y+1, 20, 3);
sr.printString(sr.width - 27, resultPos.Y+2, "Computer: ", YELLOW);
sr.printString(sr.width - 26, resultPos.Y+3, scoreC, YELLOW);
sr.printString(sr.width - 14, resultPos.Y+2, "You: ", YELLOW);
sr.printString(sr.width - 13, resultPos.Y+3, scoreU, YELLOW);
sr.render();
// program
int tscore = 0; // temporär variabel för poängen
if(compsTurn){ // om det är datorns tur att gissa?
tscore = solveres.solve(0, false);// kör igång minigame: Solver
if(tscore != -1) // om datorn löste pusslet
scoreC += tscore; // datorn får poäng
else
scoreU += 5; // annars ger vi användaren poäng för fel inmatning
}
else{ // om det är användarens tur att gissa?
tscore = creater(false); // kör igång minigame: Solver
if(tscore != -1) // om användaren inte lyckades gissa numret
scoreU += tscore; // användaren får poäng
else
scoreU += 5; // annars ger vi anändaren 5 extra poäng
}
turns++; // öka till nästa runda vi spelar.
if(!whantToContinueChallange(sr, keys))// ska de spelas igen?
whanaPlay = false; // om inte så sätts whanaPlay till false
compsTurn = !compsTurn; // byt turer om vem som skall gissa
}
// returnera antal poäng användaren är värd
return (scoreU - turns*5) + scoreC;
}
int BullsCows::creater(bool practice){// default: practice = true
Gissning random = DistinktNumber::selectDistinkt(rand()%9877 + 50000); // create random number
int guess = 50000, // användarens gissning
tryes = 10, // antal försök som användaren får
pos = 1000; // positionen som användaren kan ändra på vid nästa input
int lnPos = length(pos); // längden på pos, dvs 4
SR::PIX px; // en ScreenRender class för att skriva ut en punkt i förnstret
px.Char.AsciiChar = 'v'; // v är tecknet som skrivs ut. i PIX objectet
if(practice) // om det är practice mode så vill vi ränsa skärmen nu
sr.clearScreen(); // ränsa skärmnen
drawTable(sr); // skriv ut strukturen av tabellen för gissning och resultat(bc)
// en beskrivning om vad som förväntas av användaren
sr.printString(resultPos.X+35, resultPos.Y+3, "Number", CYAN);
sr.printString(resultPos.X+20, resultPos.Y+7, "You input a guess of the");
sr.printString(resultPos.X+20, resultPos.Y+8, "generated number by typing");
sr.printString(resultPos.X+20, resultPos.Y+9, " it in the right box.Use ");
sr.printString(resultPos.X+20, resultPos.Y+10,"the arrow keys to navigate");
sr.printString(resultPos.X+20, resultPos.Y+11,"between the numbers.");
if(practice) // om det är practice mode så säger vi det till användaren också
sr.printString(3, sr.height-3, "Practice guess numbers.", BLACK);
while(true){ // tills användaren har gissat tryes gånger eller gissat rätt.
// skriv ut gissningen som användaren nuvarande vill gissa på
sr.printString(resultPos.X+35, resultPos.Y+1, guess, CYAN);
// skriv en fyrkant runt gissningen
sr.drawRect(resultPos.X+35, resultPos.Y+0, 5, 2); // används i loopen för att skriva över 5:an i guess
// rensa positionen av pilen v
sr.printString(resultPos.X+36, resultPos.Y -1, " ");
// skriv pilen v igen på rätt position
px.Char.AsciiChar = 'v';
sr.setPixel(resultPos.X+39 - lnPos, resultPos.Y -1, &px);
sr.render(); // visa på skärmen
int num = keys.getch(); // vänta på input från användaren
// rensa statusbaren
sr.printString(sr.width/2 - 72/2, sr.height - 2, " ", GREEN);
sr.render(); // visa på skärmen
if(num >='0' && num <='9'){ // om num är ett nummer
guess -= getPos(guess, (4-lnPos), 5)*pos; // rensa positionen pos från guess
guess += pos*(num-48); // sätt positionen pos från guess
pos = (pos/10); // minska positionen med 1
if(pos == 0) // om positionen inte går att minska längre
pos = 1000; // resetta positionen till 1000;
lnPos = length(pos); // längden av pos
}
else if(num == '\n'){ // om num är enter/retur tangenten
Gissning o_guess = guess; // convertera gissningen till ett object Gissning
// bc får antal bulls och cows i random och o_guess.
int bc = solveres.BullsCowsContain(&random, &o_guess);
if(guess == DistinktNumber::selectDistinkt(guess)){ // om bc är ett distinkt nummer
if(bc%10 == 4){ // om bulls är 4
tryes = 10 - tryes; // omvandla tryes till antal försök som har gjorts
drawSucess(sr,tryes); // skriv ett medelande till användaren om att den har lyckats
sr.printString(sr.width/2 - 28/2, sr.height - 2, "Press any key to continue...", RED);
sr.render(); // visa på skärmen
while(keys.kbhit())keys.getch(); // rensa bufferten
keys.getch(); // vänta på en knapptryckning
return tryes; // returnera "poängen"
}
sr.printString(resultPos.X + 2, resultPos.Y + (10-tryes) +2, guess); // skriv ut gissningen
sr.printString(resultPos.X + 2, resultPos.Y + (10-tryes) +2, " "); // ta bort 5:an
sr.printString(resultPos.X + 10, resultPos.Y + (10-tryes) +2, bc%10, GREEN);// skriv ut bulls
sr.printString(resultPos.X + 12, resultPos.Y + (10-tryes) +2, bc/10, CYAN); // skriv ut cows
// skriv ut en hint om vad som är bulls och cows
sr.printString(sr.width/2 - 72/2, sr.height - 2, "HINT: Green clue means count of bulls and blue clue means count of cows.", GREEN);
sr.render(); // visa på skärmen
tryes--; // minska antal försök med 1
if(!tryes){ // om det inte är några försök kvar
sr.clearScreen(); // rensa skärmen och bufferten i ScreenRender
drawSucess(sr,-1); // visa ett medelande för användaren, att den har förlorat
sr.printString(sr.width/2 - 28/2, sr.height - 2, "Press any key to continue...", RED);
sr.render(); // visa på skärmen
while(keys.kbhit())keys.getch(); // rensa alla lagrade tangentnedtryckningar
keys.getch(); // vänta på en knapptryckning från användaren
if(!practice || !whantToContinueChallange(sr, keys)) // om det är en utmaning med datorn eller användaren inte vill spela igen
break;
sr.clearScreen(); // rensa skärmen
drawTable(sr); // skriv ut strukturen för tabellen med gissningar, bulls och cows
// en beskrivning om vad som förväntas av användaren
sr.printString(resultPos.X+35, resultPos.Y+3, "Number", CYAN);
sr.printString(resultPos.X+20, resultPos.Y+7, "You input a guess of the");
sr.printString(resultPos.X+20, resultPos.Y+8, "generated number by typing");
sr.printString(resultPos.X+20, resultPos.Y+9, " it in the right box.Use ");
sr.printString(resultPos.X+20, resultPos.Y+10,"the arrow keys to navigate");
sr.printString(resultPos.X+20, resultPos.Y+11,"between the numbers.");
// eftersom det är garanterat att det inte är en challange så skriver vi ut att det är practice
sr.printString(3, sr.height-3, "Practice guess numbers.", BLACK);
tryes = 10; // resetta anta försök
}
}
else{
// när det inte är ett distinkt numer så skriver vi ut att det inte är ett distinkt nummer
sr.printString(sr.width/2 - 46/2, sr.height - 2, "You need to guess a number of distinct numbers", RED);
sr.render(); // visa på skärmen
}
}
else if(num == 'q' || num == 'Q') // om användaren avbryter spelomgången med q tangenten
return -1;
else{
// för att samla ihop all tillgängnlig data så att det går att avgöra om det är en
string kp;
kp += num; // lägg till det inlästa värdet i kp
while(keys.kbhit()) // läs in alla knapptryckningar som finns i bufferten för termios
kp += keys.getch(); // lägg de inlästa värdena i kp
if(kp == VK_RIGHT){ // om de inlästa värdena matchar värdet för höger tangenten
pos = (pos/10); // minska pos positionen med 1
if(pos == 0) // om det inte går att minska mera
pos = 1000; // sätt positionen till max igen
lnPos = length(pos); // längden på positionen pos
}
else if(kp == VK_LEFT){ // om de inlästa värdena matchar värdet för vänster tangenten
pos = (pos*10); // öka positionen pos med 1
if(pos == 10000) // om det inte ska gå att öka pos med 1
pos = 1; // sätt pos till det minsta talet igen
lnPos = length(pos); // längden på positionen pos
}
}
Sleep(60); // vänta 60ms för att förhindra seg updatering
}
return -1;
}
int BullsCows::doStats(string toFile){
int max = 0, //
tal = 0;
for(DistinktNumber j = 50123; j.getNum() < 59877; j=j+1){
if(j == -1 )
break;
Gissning real(j);
int tmax = solveres.solve(&real);
if( tmax> max)
max = tmax, tal = j;
}
cout << "TAL = " << tal << ", MAX = " << max << endl;
}
int BullsCows::length(int n){
int i=n, // sätt i till talet som ska valideras
l =0; // l kommer att bli längden av l
while((i /= 10)) // så länge som i är mer än 0
l++; // öka längden l med 1
return l; // returnera längden
}
int BullsCows::getPos(int &num, int pos, int &len){
pos = len - pos - 1; // positionen inverteras eftersom talet räknas från höger till vänster
// -1 är bara där för att talet börgar med ett tal som inte skall finnas med i talet
int in=1; // vilket tal representerar positionen
for(int inj=0;inj<pos;inj++) in*=10; // in representerar nu positionen för pos
return (num%(in*10))/in; // returnerar värdet för positionen pos.
}
|
5989f6557b7608124a6e006dc6aff6899b9fa4ad
|
245724709dfc7ee5c1c2d4ce6ec55d523f78d60c
|
/src/Algorithms/FruchtermanReingold.cpp
|
6d4782518b2fffcf29c456b785bc709a1f0b1706
|
[] |
no_license
|
joemcdonnell50/Qt_NetvizGL2
|
47aeca8b3c808d96567e1986457b3014d45a891f
|
08c1929ed8735029ed40ea6ad99e4cf175d76780
|
refs/heads/master
| 2021-05-13T13:23:56.045366
| 2018-04-18T16:33:46
| 2018-04-18T16:33:46
| 116,705,618
| 0
| 0
| null | 2018-01-08T17:14:39
| 2018-01-08T17:14:39
| null |
UTF-8
|
C++
| false
| false
| 2,639
|
cpp
|
FruchtermanReingold.cpp
|
//
// Created by werl on 10/02/17.
//
#include <sys/time.h>
#include <zconf.h>
#include "../../inc/Algorithms/FruchtermanReingold.h"
FruchtermanReingold::FruchtermanReingold(Graph *g) : Algorithm(g) {
W = 40;
L = 30;
area = W * L;
t = graph->numVertices;
k = sqrt(area / (double)t);
initialPlacement();
}
void FruchtermanReingold::apply() {
calculateRepulsiveForces();
calculateAttractiveForces();
updateNodePosition();
t *= .9;
}
void FruchtermanReingold::calculateRepulsiveForces(){
Vertex *v;
Vertex *u;
for (int i = 0; i < graph->numVertices; ++i) {
v = graph->vertices[i];
v->forceX = 0;
v->forceY = 0;
for (int j = 0; j < graph->numVertices; ++j) {
if (i == j) continue;
u = graph->vertices[j];
double xDist = (v->posX - u->posX);
double yDist = (v->posY - u->posY);
double dist = sqrt((xDist * xDist) + (yDist * yDist));
if (dist < 0.00000000002) dist = 0.00000000002;
double repulsion = k * k / dist;
v->forceX += xDist / dist * repulsion;
v->forceY += yDist / dist * repulsion;
}
}
}
void FruchtermanReingold::calculateAttractiveForces(){
Vertex *v;
Vertex *u;
for (int i = 0; i < graph->numEdges; ++i) {
v = graph->edges[i]->base;
u = graph->edges[i]->connect;
double xDist = (v->posX - u->posX);
double yDist = (v->posY - u->posY);
double dist = sqrt((xDist * xDist) + (yDist * yDist));
if (dist < 0.00000000002) dist = 0.00000000002;
double attraction = dist * dist / k;
v->forceX -= xDist / dist * attraction;
v->forceY -= yDist / dist * attraction;
u->forceX += xDist / dist * attraction;
u->forceY += yDist / dist * attraction;
}
}
void FruchtermanReingold::updateNodePosition(){
Vertex *v;
for (int i = 0; i < graph->numVertices; ++i) {
v = graph->vertices[i];
v->posX += v->forceX * 0.0015;
v->posY += v->forceY * 0.0015;
}
}
void FruchtermanReingold::initialPlacement() {
char *digit = new char[64];
struct timeval time;
gettimeofday(&time, NULL);
srand(Graph::hash3(time.tv_sec, time.tv_usec, getpid()));
for (int j = 0; j < graph->numVertices; ++j) {
//sprintf(digit, "%d", j);
graph->vertices[j]->setText(digit);
graph->vertices[j]->posX = ((double) rand()) / RAND_MAX * (W) - W / 2;
graph->vertices[j]->posY = ((double) rand()) / RAND_MAX * (L) - L / 2;
graph->vertices[j]->posZ = 0;
}
}
|
a7d9dec0e8378b973875b1b7d98e39028afe75dd
|
33a600802348b155b21e919139c311f207cbc8a7
|
/src/cpp/utils.cpp
|
31cf6705475492d2d33200ff22ee8a93080ed067
|
[] |
no_license
|
oldmannt/gearsbox
|
0f48f1f256d88f199cf7c984fb0a10667aa79c21
|
27d41745844dd2795e079aaf43b46e31e10970b0
|
refs/heads/master
| 2020-04-12T06:34:12.126992
| 2016-11-05T00:16:29
| 2016-11-05T00:16:29
| 58,963,862
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 3,656
|
cpp
|
utils.cpp
|
//
// utils.cpp
// gearsbox
//
// Created by dyno on 6/23/16.
//
//
#include <fstream>
#include <chrono>
#include "macro.h"
#include "utils.hpp"
#include "async_task_pool.cpp"
using namespace gearsbox;
bool gearsbox::readJson(const std::string& param, Json::Value& config){
CHECK_RTF(param.size()>0, "param size 0");
Json::Reader reader;
const char* subfix = param.c_str()+param.size()-strlen(".json");
if (0==strcmp(subfix, ".json")){
std::ifstream ifs(param);
if (!ifs.is_open()){
G_LOG_FC(LOG_ERROR, "open file failed %s", param.c_str());
return false;
}
if (!reader.parse(ifs, config)){
std::string err = reader.getFormatedErrorMessages();
G_LOG_FC(LOG_ERROR, "read err:%s file:%s", err.c_str(), param.c_str());
return false;
}
}else if (!reader.parse(param, config)){
std::string err = reader.getFormatedErrorMessages();
G_LOG_FC(LOG_ERROR, "read err:%s param:%s", err.c_str(), param.c_str());
return false;
}
return true;
}
long long gearsbox::nowMilli(){
using namespace std::chrono;
return duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
}
bool gearsbox::writerJson(const std::string& path, Json::Value& config, bool async){
Json::FastWriter writer;
std::string str = writer.write(config);
auto async_save = [str, path](){
std::ofstream ofs;
ofs.open(path);
if (!ofs.is_open()){
G_LOG_FC(LOG_ERROR, "fs open file failed: %s", path.c_str());
return false;
}
ofs << str;
ofs.close();
};
if (async){
AsyncTaskPool::instance()->enqueue(AsyncTaskPool::TaskType::FILE, async_save, nullptr);
}
else{
async_save();
}
return true;
}
#include <mach/mach_time.h>
uint64_t subtractTimes( uint64_t elapsed )
{
static mach_timebase_info_data_t sTimebaseInfo;
// Convert to nanoseconds.
// If this is the first time we've run, get the timebase.
// We can use denom == 0 to indicate that sTimebaseInfo is
// uninitialised because it makes no sense to have a zero
// denominator is a fraction.
if ( sTimebaseInfo.denom == 0 ) {
(void) mach_timebase_info(&sTimebaseInfo);
}
// Do the maths. We hope that the multiplication doesn't
// overflow; the price you pay for working in fixed point.
uint64_t elapsedNano = elapsed * sTimebaseInfo.numer / sTimebaseInfo.denom;
return elapsedNano;
}
/*
ViewConf gearsbox::emptyViewConf(){
return std::move(ViewConf("" // std::string id_,
, ViewType::BASE // ViewType type_,
, ViewFrame(0,0,0,0) // ViewFrame frame_,
, ArgbColor(0,0,0,0) // ArgbColor bgcolor_,
, -1 // int32_t fontsize_,
, TextAlign::NONE // TextAlign textalign_,
, TextBoarder::NONE // TextBoarder textboarder_,
, "" // std::string text_,
, false // numericText
, TextKeyboard::DEFAULT// keyboardtype
, std::vector<ViewConstraint>()
, std::unordered_map<std::string, ViewConf>()
));
}
*/
|
ee59ee3b3a90a844f76725679c3661a891c70709
|
6e3b59d15607630869f518aee24c762d5dd71d06
|
/CODES/D_Binary_String_To_Subsequences.cpp
|
0157ffebd9832f72bf301725a068e92712b03119
|
[] |
no_license
|
Aman-droid/CP_Essentials
|
c74ffce2c4acc9fa6b0ebc409f9f6e9640f92c91
|
40758de037a4b380bd7d921cd3cd7c4f8fc86be1
|
refs/heads/master
| 2023-06-05T13:56:29.053495
| 2021-06-29T18:13:14
| 2021-06-29T18:13:14
| 381,141,371
| 1
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,907
|
cpp
|
D_Binary_String_To_Subsequences.cpp
|
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vpll vector<pll>
#define SZ(x) ((int)x.size())
#define FIO ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define watch(x)cout<<(#x)<<" is "<<(x)<<"\n"
#define watch2(x,y)cout<<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define mod 1000000007
#define INF (ll)(1e18)
#define all(c) (c).begin(),(c).end()
using namespace std;
ll power(ll a, ll b){//a^b
ll res=1;
a=a%mod;
while(b>0){
if(b&1){res=(res*a)%mod;b--;}
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
//-------------------soln-----------------------------//
const int mxn=2e5;
void solve(){
queue<int>zrs,one;
int n ;cin>>n;
string s;cin>>s;
int res[n]={0};
int cnt=0,tmp;
int ans=-1;
rep(i,0,n-1){
if(s[i]=='1'){
if(zrs.empty()){
cnt++;
ans=max(ans,cnt);
res[i]=cnt;
one.push(cnt);
}
else{
tmp=zrs.front();
zrs.pop();
res[i]=tmp;
one.push(tmp);
}
}
else{
if(one.empty()){
cnt++;
ans=max(ans,cnt);
res[i]=cnt;
zrs.push(cnt);
}
else{
tmp=one.front();
one.pop();
res[i]=tmp;
zrs.push(tmp);
}
}
}
cout<<ans<<endl;
rep(i,0,n-1){
cout<<res[i]<<" ";
}
cout<<endl;
}
signed main() {
FIO;
int T=1;cin>>T;
while (T--){
solve();
}
return 0;
}
|
ef8eafaf2f303fedb21a07911d72b7306d375053
|
00845730e8c3f66af4687a44f93c46295ad91db3
|
/lab5/dns/cal_ans.cpp
|
7494a83a94b4b145a0e25fe25bf675e2661d974b
|
[
"MIT"
] |
permissive
|
Yangfan-Jiang/High-Performance-Computing-Fall-2019
|
57464fb7c5f7df14055da9108b782c0c191c7c0c
|
b0292d17cbf1ce93e8df024a53721f94cefa95e4
|
refs/heads/master
| 2022-11-30T11:29:00.250326
| 2020-08-14T14:03:11
| 2020-08-14T14:03:11
| 206,923,025
| 0
| 1
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,648
|
cpp
|
cal_ans.cpp
|
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<fstream>
#include"omp.h"
#define N 32768
using namespace std;
void init_matrix(double **A, double **B, double **C, double **C2 ,int local_i, int local_j, int block_size);
void init_matrix_s(double **A, double **B, double **C);
void matrix_multi_serial(double **A, double **B, double **C);
int main() {
/* allocate contiguous memory */
double *A_storage = new double[N*N];
double *B_storage = new double[N*N];
double *C_storage = new double[N*N];
double **A = new double *[N];
double **B = new double *[N];
double **C = new double *[N];
for(int i=0; i<N; i++) {
A[i] = &A_storage[i*N];
B[i] = &B_storage[i*N];
C[i] = &C_storage[i*N];
}
init_matrix_s(A, B, C);
matrix_multi_serial(A, B, C);
ofstream fout("result.dat", ios::out);
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
fout << C[i][j] << " ";
}
fout << "\r\n";
}
fout.close();
return 0;
}
void init_matrix_s(double **A, double **B, double **C) {
# pragma omp parallel for
for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
A[i][j] = (i-0.1*j+1)*1.0/(i+j+1);
B[i][j] = (j-0.2*i+1)*1.0/(i*i+j*j+1);
C[i][j] = 0;
}
}
void matrix_multi_serial(double **A, double **B, double **C) {
int i, j, k;
for(i=0; i<N; i++) {
# pragma omp parallel for shared(A,B,C) private(k)
for(j=0; j<N; j++) {
for(k=0; k<N; k++) {
C[i][j] += A[i][k]*B[k][j];
}
}
}
}
|
74e97340c2d34ed78419645057251720c17d571f
|
4f0ecbd419ee957d65930209ef890ad391f3723e
|
/src/worker.hxx
|
ec0d74e60f3b2f028f98534647c47fc0529c8f97
|
[
"MIT"
] |
permissive
|
moskupols/mipt-parallel-labs
|
0bd0402f954ee975908a85462660620ca028082c
|
4762733d50f7e1dd46f7cdd13c4861b9f9f73e37
|
refs/heads/master
| 2016-09-11T02:47:54.059647
| 2015-09-30T02:36:39
| 2015-09-30T02:37:06
| 42,747,017
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 219
|
hxx
|
worker.hxx
|
#ifndef WORKER_HXX_INCLUDED
#define WORKER_HXX_INCLUDED
#include "tile.hxx"
namespace game_of_life
{
class Worker
{
public:
static void makeIteration(const AbstractTile& prev, AbstractTile& next);
};
}
#endif
|
91dba47cd455067e0f0a8074f0e237483454d8f4
|
08509d1d559f3f7eab7495cd4e072f229488166a
|
/Solution/Entity/SpawnpointComponentData.h
|
c5ed3200c3444f8f1cd7e0709fbb2f8f467d575c
|
[] |
no_license
|
LastVision/DistortionGamesFPS
|
8a9da37990c68bb6ba193a289633f91ffa47bd6b
|
e26bd778b3ce16e01e6c9d67ad8e0ce7d1f0f6e0
|
refs/heads/master
| 2021-06-01T08:32:46.430309
| 2016-04-28T10:34:38
| 2016-04-28T10:34:38
| 51,527,472
| 2
| 3
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 270
|
h
|
SpawnpointComponentData.h
|
#pragma once
#include <GrowingArray.h>
struct SpawnpointComponentData
{
bool myExistsInEntity = false;
CU::GrowingArray<std::string> myUnitTypes;
float mySpawnpointLifetime = 0.f;
float mySpawnInterval = 0.f;
int mySpawnPerInterval = 0;
int myUnitCount = 0;
};
|
8486fd20c3ba98a72f597f10e0cc80a20abe62c1
|
2f6a9ff787b9eb2ababc9bb39e15f1349fefa3d2
|
/inet/src/inet/physicallayer/modulation/Qam1024Modulation.cc
|
c8c49979ce95b72c7f8031978d97c0b340263924
|
[
"BSD-3-Clause",
"MPL-2.0",
"LicenseRef-scancode-free-unknown"
] |
permissive
|
ntanetani/quisp
|
97f9c2d0a8d3affbc709452e98c02c568f5fe8fd
|
47501a9e9adbd6adfb05a1c98624870b004799ea
|
refs/heads/master
| 2023-03-10T08:05:30.044698
| 2022-06-14T17:29:28
| 2022-06-14T17:29:28
| 247,196,429
| 0
| 1
|
BSD-3-Clause
| 2023-02-27T03:27:22
| 2020-03-14T02:16:19
|
C++
|
UTF-8
|
C++
| false
| false
| 29,262
|
cc
|
Qam1024Modulation.cc
|
//
// Copyright (C) 2014 OpenSim Ltd.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
#include "inet/physicallayer/modulation/Qam1024Modulation.h"
namespace inet {
namespace physicallayer {
const double k = 1 / sqrt(170);
// generated by a small script according to http://patentimages.storage.googleapis.com/WO2003058904A1/imgf000014_0001.png
const std::vector<ApskSymbol> Qam1024Modulation::constellation = {
k * ApskSymbol(-31,-31),
k * ApskSymbol(-31,-29),
k * ApskSymbol(-31,-25),
k * ApskSymbol(-31,-27),
k * ApskSymbol(-31,-17),
k * ApskSymbol(-31,-19),
k * ApskSymbol(-31,-23),
k * ApskSymbol(-31,-21),
k * ApskSymbol(-31,-1),
k * ApskSymbol(-31,-3),
k * ApskSymbol(-31,-7),
k * ApskSymbol(-31,-5),
k * ApskSymbol(-31,-15),
k * ApskSymbol(-31,-13),
k * ApskSymbol(-31,-9),
k * ApskSymbol(-31,-11),
k * ApskSymbol(-31,31),
k * ApskSymbol(-31,29),
k * ApskSymbol(-31,25),
k * ApskSymbol(-31,27),
k * ApskSymbol(-31,17),
k * ApskSymbol(-31,19),
k * ApskSymbol(-31,23),
k * ApskSymbol(-31,21),
k * ApskSymbol(-31,1),
k * ApskSymbol(-31,3),
k * ApskSymbol(-31,7),
k * ApskSymbol(-31,5),
k * ApskSymbol(-31,15),
k * ApskSymbol(-31,13),
k * ApskSymbol(-31,9),
k * ApskSymbol(-31,11),
k * ApskSymbol(-29,-31),
k * ApskSymbol(-29,-29),
k * ApskSymbol(-29,-25),
k * ApskSymbol(-29,-27),
k * ApskSymbol(-29,-17),
k * ApskSymbol(-29,-19),
k * ApskSymbol(-29,-23),
k * ApskSymbol(-29,-21),
k * ApskSymbol(-29,-1),
k * ApskSymbol(-29,-3),
k * ApskSymbol(-29,-7),
k * ApskSymbol(-29,-5),
k * ApskSymbol(-29,-15),
k * ApskSymbol(-29,-13),
k * ApskSymbol(-29,-9),
k * ApskSymbol(-29,-11),
k * ApskSymbol(-29,31),
k * ApskSymbol(-29,29),
k * ApskSymbol(-29,25),
k * ApskSymbol(-29,27),
k * ApskSymbol(-29,17),
k * ApskSymbol(-29,19),
k * ApskSymbol(-29,23),
k * ApskSymbol(-29,21),
k * ApskSymbol(-29,1),
k * ApskSymbol(-29,3),
k * ApskSymbol(-29,7),
k * ApskSymbol(-29,5),
k * ApskSymbol(-29,15),
k * ApskSymbol(-29,13),
k * ApskSymbol(-29,9),
k * ApskSymbol(-29,11),
k * ApskSymbol(-25,-31),
k * ApskSymbol(-25,-29),
k * ApskSymbol(-25,-25),
k * ApskSymbol(-25,-27),
k * ApskSymbol(-25,-17),
k * ApskSymbol(-25,-19),
k * ApskSymbol(-25,-23),
k * ApskSymbol(-25,-21),
k * ApskSymbol(-25,-1),
k * ApskSymbol(-25,-3),
k * ApskSymbol(-25,-7),
k * ApskSymbol(-25,-5),
k * ApskSymbol(-25,-15),
k * ApskSymbol(-25,-13),
k * ApskSymbol(-25,-9),
k * ApskSymbol(-25,-11),
k * ApskSymbol(-25,31),
k * ApskSymbol(-25,29),
k * ApskSymbol(-25,25),
k * ApskSymbol(-25,27),
k * ApskSymbol(-25,17),
k * ApskSymbol(-25,19),
k * ApskSymbol(-25,23),
k * ApskSymbol(-25,21),
k * ApskSymbol(-25,1),
k * ApskSymbol(-25,3),
k * ApskSymbol(-25,7),
k * ApskSymbol(-25,5),
k * ApskSymbol(-25,15),
k * ApskSymbol(-25,13),
k * ApskSymbol(-25,9),
k * ApskSymbol(-25,11),
k * ApskSymbol(-27,-31),
k * ApskSymbol(-27,-29),
k * ApskSymbol(-27,-25),
k * ApskSymbol(-27,-27),
k * ApskSymbol(-27,-17),
k * ApskSymbol(-27,-19),
k * ApskSymbol(-27,-23),
k * ApskSymbol(-27,-21),
k * ApskSymbol(-27,-1),
k * ApskSymbol(-27,-3),
k * ApskSymbol(-27,-7),
k * ApskSymbol(-27,-5),
k * ApskSymbol(-27,-15),
k * ApskSymbol(-27,-13),
k * ApskSymbol(-27,-9),
k * ApskSymbol(-27,-11),
k * ApskSymbol(-27,31),
k * ApskSymbol(-27,29),
k * ApskSymbol(-27,25),
k * ApskSymbol(-27,27),
k * ApskSymbol(-27,17),
k * ApskSymbol(-27,19),
k * ApskSymbol(-27,23),
k * ApskSymbol(-27,21),
k * ApskSymbol(-27,1),
k * ApskSymbol(-27,3),
k * ApskSymbol(-27,7),
k * ApskSymbol(-27,5),
k * ApskSymbol(-27,15),
k * ApskSymbol(-27,13),
k * ApskSymbol(-27,9),
k * ApskSymbol(-27,11),
k * ApskSymbol(-17,-31),
k * ApskSymbol(-17,-29),
k * ApskSymbol(-17,-25),
k * ApskSymbol(-17,-27),
k * ApskSymbol(-17,-17),
k * ApskSymbol(-17,-19),
k * ApskSymbol(-17,-23),
k * ApskSymbol(-17,-21),
k * ApskSymbol(-17,-1),
k * ApskSymbol(-17,-3),
k * ApskSymbol(-17,-7),
k * ApskSymbol(-17,-5),
k * ApskSymbol(-17,-15),
k * ApskSymbol(-17,-13),
k * ApskSymbol(-17,-9),
k * ApskSymbol(-17,-11),
k * ApskSymbol(-17,31),
k * ApskSymbol(-17,29),
k * ApskSymbol(-17,25),
k * ApskSymbol(-17,27),
k * ApskSymbol(-17,17),
k * ApskSymbol(-17,19),
k * ApskSymbol(-17,23),
k * ApskSymbol(-17,21),
k * ApskSymbol(-17,1),
k * ApskSymbol(-17,3),
k * ApskSymbol(-17,7),
k * ApskSymbol(-17,5),
k * ApskSymbol(-17,15),
k * ApskSymbol(-17,13),
k * ApskSymbol(-17,9),
k * ApskSymbol(-17,11),
k * ApskSymbol(-19,-31),
k * ApskSymbol(-19,-29),
k * ApskSymbol(-19,-25),
k * ApskSymbol(-19,-27),
k * ApskSymbol(-19,-17),
k * ApskSymbol(-19,-19),
k * ApskSymbol(-19,-23),
k * ApskSymbol(-19,-21),
k * ApskSymbol(-19,-1),
k * ApskSymbol(-19,-3),
k * ApskSymbol(-19,-7),
k * ApskSymbol(-19,-5),
k * ApskSymbol(-19,-15),
k * ApskSymbol(-19,-13),
k * ApskSymbol(-19,-9),
k * ApskSymbol(-19,-11),
k * ApskSymbol(-19,31),
k * ApskSymbol(-19,29),
k * ApskSymbol(-19,25),
k * ApskSymbol(-19,27),
k * ApskSymbol(-19,17),
k * ApskSymbol(-19,19),
k * ApskSymbol(-19,23),
k * ApskSymbol(-19,21),
k * ApskSymbol(-19,1),
k * ApskSymbol(-19,3),
k * ApskSymbol(-19,7),
k * ApskSymbol(-19,5),
k * ApskSymbol(-19,15),
k * ApskSymbol(-19,13),
k * ApskSymbol(-19,9),
k * ApskSymbol(-19,11),
k * ApskSymbol(-23,-31),
k * ApskSymbol(-23,-29),
k * ApskSymbol(-23,-25),
k * ApskSymbol(-23,-27),
k * ApskSymbol(-23,-17),
k * ApskSymbol(-23,-19),
k * ApskSymbol(-23,-23),
k * ApskSymbol(-23,-21),
k * ApskSymbol(-23,-1),
k * ApskSymbol(-23,-3),
k * ApskSymbol(-23,-7),
k * ApskSymbol(-23,-5),
k * ApskSymbol(-23,-15),
k * ApskSymbol(-23,-13),
k * ApskSymbol(-23,-9),
k * ApskSymbol(-23,-11),
k * ApskSymbol(-23,31),
k * ApskSymbol(-23,29),
k * ApskSymbol(-23,25),
k * ApskSymbol(-23,27),
k * ApskSymbol(-23,17),
k * ApskSymbol(-23,19),
k * ApskSymbol(-23,23),
k * ApskSymbol(-23,21),
k * ApskSymbol(-23,1),
k * ApskSymbol(-23,3),
k * ApskSymbol(-23,7),
k * ApskSymbol(-23,5),
k * ApskSymbol(-23,15),
k * ApskSymbol(-23,13),
k * ApskSymbol(-23,9),
k * ApskSymbol(-23,11),
k * ApskSymbol(-21,-31),
k * ApskSymbol(-21,-29),
k * ApskSymbol(-21,-25),
k * ApskSymbol(-21,-27),
k * ApskSymbol(-21,-17),
k * ApskSymbol(-21,-19),
k * ApskSymbol(-21,-23),
k * ApskSymbol(-21,-21),
k * ApskSymbol(-21,-1),
k * ApskSymbol(-21,-3),
k * ApskSymbol(-21,-7),
k * ApskSymbol(-21,-5),
k * ApskSymbol(-21,-15),
k * ApskSymbol(-21,-13),
k * ApskSymbol(-21,-9),
k * ApskSymbol(-21,-11),
k * ApskSymbol(-21,31),
k * ApskSymbol(-21,29),
k * ApskSymbol(-21,25),
k * ApskSymbol(-21,27),
k * ApskSymbol(-21,17),
k * ApskSymbol(-21,19),
k * ApskSymbol(-21,23),
k * ApskSymbol(-21,21),
k * ApskSymbol(-21,1),
k * ApskSymbol(-21,3),
k * ApskSymbol(-21,7),
k * ApskSymbol(-21,5),
k * ApskSymbol(-21,15),
k * ApskSymbol(-21,13),
k * ApskSymbol(-21,9),
k * ApskSymbol(-21,11),
k * ApskSymbol(-1,-31),
k * ApskSymbol(-1,-29),
k * ApskSymbol(-1,-25),
k * ApskSymbol(-1,-27),
k * ApskSymbol(-1,-17),
k * ApskSymbol(-1,-19),
k * ApskSymbol(-1,-23),
k * ApskSymbol(-1,-21),
k * ApskSymbol(-1,-1),
k * ApskSymbol(-1,-3),
k * ApskSymbol(-1,-7),
k * ApskSymbol(-1,-5),
k * ApskSymbol(-1,-15),
k * ApskSymbol(-1,-13),
k * ApskSymbol(-1,-9),
k * ApskSymbol(-1,-11),
k * ApskSymbol(-1,31),
k * ApskSymbol(-1,29),
k * ApskSymbol(-1,25),
k * ApskSymbol(-1,27),
k * ApskSymbol(-1,17),
k * ApskSymbol(-1,19),
k * ApskSymbol(-1,23),
k * ApskSymbol(-1,21),
k * ApskSymbol(-1,1),
k * ApskSymbol(-1,3),
k * ApskSymbol(-1,7),
k * ApskSymbol(-1,5),
k * ApskSymbol(-1,15),
k * ApskSymbol(-1,13),
k * ApskSymbol(-1,9),
k * ApskSymbol(-1,11),
k * ApskSymbol(-3,-31),
k * ApskSymbol(-3,-29),
k * ApskSymbol(-3,-25),
k * ApskSymbol(-3,-27),
k * ApskSymbol(-3,-17),
k * ApskSymbol(-3,-19),
k * ApskSymbol(-3,-23),
k * ApskSymbol(-3,-21),
k * ApskSymbol(-3,-1),
k * ApskSymbol(-3,-3),
k * ApskSymbol(-3,-7),
k * ApskSymbol(-3,-5),
k * ApskSymbol(-3,-15),
k * ApskSymbol(-3,-13),
k * ApskSymbol(-3,-9),
k * ApskSymbol(-3,-11),
k * ApskSymbol(-3,31),
k * ApskSymbol(-3,29),
k * ApskSymbol(-3,25),
k * ApskSymbol(-3,27),
k * ApskSymbol(-3,17),
k * ApskSymbol(-3,19),
k * ApskSymbol(-3,23),
k * ApskSymbol(-3,21),
k * ApskSymbol(-3,1),
k * ApskSymbol(-3,3),
k * ApskSymbol(-3,7),
k * ApskSymbol(-3,5),
k * ApskSymbol(-3,15),
k * ApskSymbol(-3,13),
k * ApskSymbol(-3,9),
k * ApskSymbol(-3,11),
k * ApskSymbol(-7,-31),
k * ApskSymbol(-7,-29),
k * ApskSymbol(-7,-25),
k * ApskSymbol(-7,-27),
k * ApskSymbol(-7,-17),
k * ApskSymbol(-7,-19),
k * ApskSymbol(-7,-23),
k * ApskSymbol(-7,-21),
k * ApskSymbol(-7,-1),
k * ApskSymbol(-7,-3),
k * ApskSymbol(-7,-7),
k * ApskSymbol(-7,-5),
k * ApskSymbol(-7,-15),
k * ApskSymbol(-7,-13),
k * ApskSymbol(-7,-9),
k * ApskSymbol(-7,-11),
k * ApskSymbol(-7,31),
k * ApskSymbol(-7,29),
k * ApskSymbol(-7,25),
k * ApskSymbol(-7,27),
k * ApskSymbol(-7,17),
k * ApskSymbol(-7,19),
k * ApskSymbol(-7,23),
k * ApskSymbol(-7,21),
k * ApskSymbol(-7,1),
k * ApskSymbol(-7,3),
k * ApskSymbol(-7,7),
k * ApskSymbol(-7,5),
k * ApskSymbol(-7,15),
k * ApskSymbol(-7,13),
k * ApskSymbol(-7,9),
k * ApskSymbol(-7,11),
k * ApskSymbol(-5,-31),
k * ApskSymbol(-5,-29),
k * ApskSymbol(-5,-25),
k * ApskSymbol(-5,-27),
k * ApskSymbol(-5,-17),
k * ApskSymbol(-5,-19),
k * ApskSymbol(-5,-23),
k * ApskSymbol(-5,-21),
k * ApskSymbol(-5,-1),
k * ApskSymbol(-5,-3),
k * ApskSymbol(-5,-7),
k * ApskSymbol(-5,-5),
k * ApskSymbol(-5,-15),
k * ApskSymbol(-5,-13),
k * ApskSymbol(-5,-9),
k * ApskSymbol(-5,-11),
k * ApskSymbol(-5,31),
k * ApskSymbol(-5,29),
k * ApskSymbol(-5,25),
k * ApskSymbol(-5,27),
k * ApskSymbol(-5,17),
k * ApskSymbol(-5,19),
k * ApskSymbol(-5,23),
k * ApskSymbol(-5,21),
k * ApskSymbol(-5,1),
k * ApskSymbol(-5,3),
k * ApskSymbol(-5,7),
k * ApskSymbol(-5,5),
k * ApskSymbol(-5,15),
k * ApskSymbol(-5,13),
k * ApskSymbol(-5,9),
k * ApskSymbol(-5,11),
k * ApskSymbol(-15,-31),
k * ApskSymbol(-15,-29),
k * ApskSymbol(-15,-25),
k * ApskSymbol(-15,-27),
k * ApskSymbol(-15,-17),
k * ApskSymbol(-15,-19),
k * ApskSymbol(-15,-23),
k * ApskSymbol(-15,-21),
k * ApskSymbol(-15,-1),
k * ApskSymbol(-15,-3),
k * ApskSymbol(-15,-7),
k * ApskSymbol(-15,-5),
k * ApskSymbol(-15,-15),
k * ApskSymbol(-15,-13),
k * ApskSymbol(-15,-9),
k * ApskSymbol(-15,-11),
k * ApskSymbol(-15,31),
k * ApskSymbol(-15,29),
k * ApskSymbol(-15,25),
k * ApskSymbol(-15,27),
k * ApskSymbol(-15,17),
k * ApskSymbol(-15,19),
k * ApskSymbol(-15,23),
k * ApskSymbol(-15,21),
k * ApskSymbol(-15,1),
k * ApskSymbol(-15,3),
k * ApskSymbol(-15,7),
k * ApskSymbol(-15,5),
k * ApskSymbol(-15,15),
k * ApskSymbol(-15,13),
k * ApskSymbol(-15,9),
k * ApskSymbol(-15,11),
k * ApskSymbol(-13,-31),
k * ApskSymbol(-13,-29),
k * ApskSymbol(-13,-25),
k * ApskSymbol(-13,-27),
k * ApskSymbol(-13,-17),
k * ApskSymbol(-13,-19),
k * ApskSymbol(-13,-23),
k * ApskSymbol(-13,-21),
k * ApskSymbol(-13,-1),
k * ApskSymbol(-13,-3),
k * ApskSymbol(-13,-7),
k * ApskSymbol(-13,-5),
k * ApskSymbol(-13,-15),
k * ApskSymbol(-13,-13),
k * ApskSymbol(-13,-9),
k * ApskSymbol(-13,-11),
k * ApskSymbol(-13,31),
k * ApskSymbol(-13,29),
k * ApskSymbol(-13,25),
k * ApskSymbol(-13,27),
k * ApskSymbol(-13,17),
k * ApskSymbol(-13,19),
k * ApskSymbol(-13,23),
k * ApskSymbol(-13,21),
k * ApskSymbol(-13,1),
k * ApskSymbol(-13,3),
k * ApskSymbol(-13,7),
k * ApskSymbol(-13,5),
k * ApskSymbol(-13,15),
k * ApskSymbol(-13,13),
k * ApskSymbol(-13,9),
k * ApskSymbol(-13,11),
k * ApskSymbol(-9,-31),
k * ApskSymbol(-9,-29),
k * ApskSymbol(-9,-25),
k * ApskSymbol(-9,-27),
k * ApskSymbol(-9,-17),
k * ApskSymbol(-9,-19),
k * ApskSymbol(-9,-23),
k * ApskSymbol(-9,-21),
k * ApskSymbol(-9,-1),
k * ApskSymbol(-9,-3),
k * ApskSymbol(-9,-7),
k * ApskSymbol(-9,-5),
k * ApskSymbol(-9,-15),
k * ApskSymbol(-9,-13),
k * ApskSymbol(-9,-9),
k * ApskSymbol(-9,-11),
k * ApskSymbol(-9,31),
k * ApskSymbol(-9,29),
k * ApskSymbol(-9,25),
k * ApskSymbol(-9,27),
k * ApskSymbol(-9,17),
k * ApskSymbol(-9,19),
k * ApskSymbol(-9,23),
k * ApskSymbol(-9,21),
k * ApskSymbol(-9,1),
k * ApskSymbol(-9,3),
k * ApskSymbol(-9,7),
k * ApskSymbol(-9,5),
k * ApskSymbol(-9,15),
k * ApskSymbol(-9,13),
k * ApskSymbol(-9,9),
k * ApskSymbol(-9,11),
k * ApskSymbol(-11,-31),
k * ApskSymbol(-11,-29),
k * ApskSymbol(-11,-25),
k * ApskSymbol(-11,-27),
k * ApskSymbol(-11,-17),
k * ApskSymbol(-11,-19),
k * ApskSymbol(-11,-23),
k * ApskSymbol(-11,-21),
k * ApskSymbol(-11,-1),
k * ApskSymbol(-11,-3),
k * ApskSymbol(-11,-7),
k * ApskSymbol(-11,-5),
k * ApskSymbol(-11,-15),
k * ApskSymbol(-11,-13),
k * ApskSymbol(-11,-9),
k * ApskSymbol(-11,-11),
k * ApskSymbol(-11,31),
k * ApskSymbol(-11,29),
k * ApskSymbol(-11,25),
k * ApskSymbol(-11,27),
k * ApskSymbol(-11,17),
k * ApskSymbol(-11,19),
k * ApskSymbol(-11,23),
k * ApskSymbol(-11,21),
k * ApskSymbol(-11,1),
k * ApskSymbol(-11,3),
k * ApskSymbol(-11,7),
k * ApskSymbol(-11,5),
k * ApskSymbol(-11,15),
k * ApskSymbol(-11,13),
k * ApskSymbol(-11,9),
k * ApskSymbol(-11,11),
k * ApskSymbol(31,-31),
k * ApskSymbol(31,-29),
k * ApskSymbol(31,-25),
k * ApskSymbol(31,-27),
k * ApskSymbol(31,-17),
k * ApskSymbol(31,-19),
k * ApskSymbol(31,-23),
k * ApskSymbol(31,-21),
k * ApskSymbol(31,-1),
k * ApskSymbol(31,-3),
k * ApskSymbol(31,-7),
k * ApskSymbol(31,-5),
k * ApskSymbol(31,-15),
k * ApskSymbol(31,-13),
k * ApskSymbol(31,-9),
k * ApskSymbol(31,-11),
k * ApskSymbol(31,31),
k * ApskSymbol(31,29),
k * ApskSymbol(31,25),
k * ApskSymbol(31,27),
k * ApskSymbol(31,17),
k * ApskSymbol(31,19),
k * ApskSymbol(31,23),
k * ApskSymbol(31,21),
k * ApskSymbol(31,1),
k * ApskSymbol(31,3),
k * ApskSymbol(31,7),
k * ApskSymbol(31,5),
k * ApskSymbol(31,15),
k * ApskSymbol(31,13),
k * ApskSymbol(31,9),
k * ApskSymbol(31,11),
k * ApskSymbol(29,-31),
k * ApskSymbol(29,-29),
k * ApskSymbol(29,-25),
k * ApskSymbol(29,-27),
k * ApskSymbol(29,-17),
k * ApskSymbol(29,-19),
k * ApskSymbol(29,-23),
k * ApskSymbol(29,-21),
k * ApskSymbol(29,-1),
k * ApskSymbol(29,-3),
k * ApskSymbol(29,-7),
k * ApskSymbol(29,-5),
k * ApskSymbol(29,-15),
k * ApskSymbol(29,-13),
k * ApskSymbol(29,-9),
k * ApskSymbol(29,-11),
k * ApskSymbol(29,31),
k * ApskSymbol(29,29),
k * ApskSymbol(29,25),
k * ApskSymbol(29,27),
k * ApskSymbol(29,17),
k * ApskSymbol(29,19),
k * ApskSymbol(29,23),
k * ApskSymbol(29,21),
k * ApskSymbol(29,1),
k * ApskSymbol(29,3),
k * ApskSymbol(29,7),
k * ApskSymbol(29,5),
k * ApskSymbol(29,15),
k * ApskSymbol(29,13),
k * ApskSymbol(29,9),
k * ApskSymbol(29,11),
k * ApskSymbol(25,-31),
k * ApskSymbol(25,-29),
k * ApskSymbol(25,-25),
k * ApskSymbol(25,-27),
k * ApskSymbol(25,-17),
k * ApskSymbol(25,-19),
k * ApskSymbol(25,-23),
k * ApskSymbol(25,-21),
k * ApskSymbol(25,-1),
k * ApskSymbol(25,-3),
k * ApskSymbol(25,-7),
k * ApskSymbol(25,-5),
k * ApskSymbol(25,-15),
k * ApskSymbol(25,-13),
k * ApskSymbol(25,-9),
k * ApskSymbol(25,-11),
k * ApskSymbol(25,31),
k * ApskSymbol(25,29),
k * ApskSymbol(25,25),
k * ApskSymbol(25,27),
k * ApskSymbol(25,17),
k * ApskSymbol(25,19),
k * ApskSymbol(25,23),
k * ApskSymbol(25,21),
k * ApskSymbol(25,1),
k * ApskSymbol(25,3),
k * ApskSymbol(25,7),
k * ApskSymbol(25,5),
k * ApskSymbol(25,15),
k * ApskSymbol(25,13),
k * ApskSymbol(25,9),
k * ApskSymbol(25,11),
k * ApskSymbol(27,-31),
k * ApskSymbol(27,-29),
k * ApskSymbol(27,-25),
k * ApskSymbol(27,-27),
k * ApskSymbol(27,-17),
k * ApskSymbol(27,-19),
k * ApskSymbol(27,-23),
k * ApskSymbol(27,-21),
k * ApskSymbol(27,-1),
k * ApskSymbol(27,-3),
k * ApskSymbol(27,-7),
k * ApskSymbol(27,-5),
k * ApskSymbol(27,-15),
k * ApskSymbol(27,-13),
k * ApskSymbol(27,-9),
k * ApskSymbol(27,-11),
k * ApskSymbol(27,31),
k * ApskSymbol(27,29),
k * ApskSymbol(27,25),
k * ApskSymbol(27,27),
k * ApskSymbol(27,17),
k * ApskSymbol(27,19),
k * ApskSymbol(27,23),
k * ApskSymbol(27,21),
k * ApskSymbol(27,1),
k * ApskSymbol(27,3),
k * ApskSymbol(27,7),
k * ApskSymbol(27,5),
k * ApskSymbol(27,15),
k * ApskSymbol(27,13),
k * ApskSymbol(27,9),
k * ApskSymbol(27,11),
k * ApskSymbol(17,-31),
k * ApskSymbol(17,-29),
k * ApskSymbol(17,-25),
k * ApskSymbol(17,-27),
k * ApskSymbol(17,-17),
k * ApskSymbol(17,-19),
k * ApskSymbol(17,-23),
k * ApskSymbol(17,-21),
k * ApskSymbol(17,-1),
k * ApskSymbol(17,-3),
k * ApskSymbol(17,-7),
k * ApskSymbol(17,-5),
k * ApskSymbol(17,-15),
k * ApskSymbol(17,-13),
k * ApskSymbol(17,-9),
k * ApskSymbol(17,-11),
k * ApskSymbol(17,31),
k * ApskSymbol(17,29),
k * ApskSymbol(17,25),
k * ApskSymbol(17,27),
k * ApskSymbol(17,17),
k * ApskSymbol(17,19),
k * ApskSymbol(17,23),
k * ApskSymbol(17,21),
k * ApskSymbol(17,1),
k * ApskSymbol(17,3),
k * ApskSymbol(17,7),
k * ApskSymbol(17,5),
k * ApskSymbol(17,15),
k * ApskSymbol(17,13),
k * ApskSymbol(17,9),
k * ApskSymbol(17,11),
k * ApskSymbol(19,-31),
k * ApskSymbol(19,-29),
k * ApskSymbol(19,-25),
k * ApskSymbol(19,-27),
k * ApskSymbol(19,-17),
k * ApskSymbol(19,-19),
k * ApskSymbol(19,-23),
k * ApskSymbol(19,-21),
k * ApskSymbol(19,-1),
k * ApskSymbol(19,-3),
k * ApskSymbol(19,-7),
k * ApskSymbol(19,-5),
k * ApskSymbol(19,-15),
k * ApskSymbol(19,-13),
k * ApskSymbol(19,-9),
k * ApskSymbol(19,-11),
k * ApskSymbol(19,31),
k * ApskSymbol(19,29),
k * ApskSymbol(19,25),
k * ApskSymbol(19,27),
k * ApskSymbol(19,17),
k * ApskSymbol(19,19),
k * ApskSymbol(19,23),
k * ApskSymbol(19,21),
k * ApskSymbol(19,1),
k * ApskSymbol(19,3),
k * ApskSymbol(19,7),
k * ApskSymbol(19,5),
k * ApskSymbol(19,15),
k * ApskSymbol(19,13),
k * ApskSymbol(19,9),
k * ApskSymbol(19,11),
k * ApskSymbol(23,-31),
k * ApskSymbol(23,-29),
k * ApskSymbol(23,-25),
k * ApskSymbol(23,-27),
k * ApskSymbol(23,-17),
k * ApskSymbol(23,-19),
k * ApskSymbol(23,-23),
k * ApskSymbol(23,-21),
k * ApskSymbol(23,-1),
k * ApskSymbol(23,-3),
k * ApskSymbol(23,-7),
k * ApskSymbol(23,-5),
k * ApskSymbol(23,-15),
k * ApskSymbol(23,-13),
k * ApskSymbol(23,-9),
k * ApskSymbol(23,-11),
k * ApskSymbol(23,31),
k * ApskSymbol(23,29),
k * ApskSymbol(23,25),
k * ApskSymbol(23,27),
k * ApskSymbol(23,17),
k * ApskSymbol(23,19),
k * ApskSymbol(23,23),
k * ApskSymbol(23,21),
k * ApskSymbol(23,1),
k * ApskSymbol(23,3),
k * ApskSymbol(23,7),
k * ApskSymbol(23,5),
k * ApskSymbol(23,15),
k * ApskSymbol(23,13),
k * ApskSymbol(23,9),
k * ApskSymbol(23,11),
k * ApskSymbol(21,-31),
k * ApskSymbol(21,-29),
k * ApskSymbol(21,-25),
k * ApskSymbol(21,-27),
k * ApskSymbol(21,-17),
k * ApskSymbol(21,-19),
k * ApskSymbol(21,-23),
k * ApskSymbol(21,-21),
k * ApskSymbol(21,-1),
k * ApskSymbol(21,-3),
k * ApskSymbol(21,-7),
k * ApskSymbol(21,-5),
k * ApskSymbol(21,-15),
k * ApskSymbol(21,-13),
k * ApskSymbol(21,-9),
k * ApskSymbol(21,-11),
k * ApskSymbol(21,31),
k * ApskSymbol(21,29),
k * ApskSymbol(21,25),
k * ApskSymbol(21,27),
k * ApskSymbol(21,17),
k * ApskSymbol(21,19),
k * ApskSymbol(21,23),
k * ApskSymbol(21,21),
k * ApskSymbol(21,1),
k * ApskSymbol(21,3),
k * ApskSymbol(21,7),
k * ApskSymbol(21,5),
k * ApskSymbol(21,15),
k * ApskSymbol(21,13),
k * ApskSymbol(21,9),
k * ApskSymbol(21,11),
k * ApskSymbol(1,-31),
k * ApskSymbol(1,-29),
k * ApskSymbol(1,-25),
k * ApskSymbol(1,-27),
k * ApskSymbol(1,-17),
k * ApskSymbol(1,-19),
k * ApskSymbol(1,-23),
k * ApskSymbol(1,-21),
k * ApskSymbol(1,-1),
k * ApskSymbol(1,-3),
k * ApskSymbol(1,-7),
k * ApskSymbol(1,-5),
k * ApskSymbol(1,-15),
k * ApskSymbol(1,-13),
k * ApskSymbol(1,-9),
k * ApskSymbol(1,-11),
k * ApskSymbol(1,31),
k * ApskSymbol(1,29),
k * ApskSymbol(1,25),
k * ApskSymbol(1,27),
k * ApskSymbol(1,17),
k * ApskSymbol(1,19),
k * ApskSymbol(1,23),
k * ApskSymbol(1,21),
k * ApskSymbol(1,1),
k * ApskSymbol(1,3),
k * ApskSymbol(1,7),
k * ApskSymbol(1,5),
k * ApskSymbol(1,15),
k * ApskSymbol(1,13),
k * ApskSymbol(1,9),
k * ApskSymbol(1,11),
k * ApskSymbol(3,-31),
k * ApskSymbol(3,-29),
k * ApskSymbol(3,-25),
k * ApskSymbol(3,-27),
k * ApskSymbol(3,-17),
k * ApskSymbol(3,-19),
k * ApskSymbol(3,-23),
k * ApskSymbol(3,-21),
k * ApskSymbol(3,-1),
k * ApskSymbol(3,-3),
k * ApskSymbol(3,-7),
k * ApskSymbol(3,-5),
k * ApskSymbol(3,-15),
k * ApskSymbol(3,-13),
k * ApskSymbol(3,-9),
k * ApskSymbol(3,-11),
k * ApskSymbol(3,31),
k * ApskSymbol(3,29),
k * ApskSymbol(3,25),
k * ApskSymbol(3,27),
k * ApskSymbol(3,17),
k * ApskSymbol(3,19),
k * ApskSymbol(3,23),
k * ApskSymbol(3,21),
k * ApskSymbol(3,1),
k * ApskSymbol(3,3),
k * ApskSymbol(3,7),
k * ApskSymbol(3,5),
k * ApskSymbol(3,15),
k * ApskSymbol(3,13),
k * ApskSymbol(3,9),
k * ApskSymbol(3,11),
k * ApskSymbol(7,-31),
k * ApskSymbol(7,-29),
k * ApskSymbol(7,-25),
k * ApskSymbol(7,-27),
k * ApskSymbol(7,-17),
k * ApskSymbol(7,-19),
k * ApskSymbol(7,-23),
k * ApskSymbol(7,-21),
k * ApskSymbol(7,-1),
k * ApskSymbol(7,-3),
k * ApskSymbol(7,-7),
k * ApskSymbol(7,-5),
k * ApskSymbol(7,-15),
k * ApskSymbol(7,-13),
k * ApskSymbol(7,-9),
k * ApskSymbol(7,-11),
k * ApskSymbol(7,31),
k * ApskSymbol(7,29),
k * ApskSymbol(7,25),
k * ApskSymbol(7,27),
k * ApskSymbol(7,17),
k * ApskSymbol(7,19),
k * ApskSymbol(7,23),
k * ApskSymbol(7,21),
k * ApskSymbol(7,1),
k * ApskSymbol(7,3),
k * ApskSymbol(7,7),
k * ApskSymbol(7,5),
k * ApskSymbol(7,15),
k * ApskSymbol(7,13),
k * ApskSymbol(7,9),
k * ApskSymbol(7,11),
k * ApskSymbol(5,-31),
k * ApskSymbol(5,-29),
k * ApskSymbol(5,-25),
k * ApskSymbol(5,-27),
k * ApskSymbol(5,-17),
k * ApskSymbol(5,-19),
k * ApskSymbol(5,-23),
k * ApskSymbol(5,-21),
k * ApskSymbol(5,-1),
k * ApskSymbol(5,-3),
k * ApskSymbol(5,-7),
k * ApskSymbol(5,-5),
k * ApskSymbol(5,-15),
k * ApskSymbol(5,-13),
k * ApskSymbol(5,-9),
k * ApskSymbol(5,-11),
k * ApskSymbol(5,31),
k * ApskSymbol(5,29),
k * ApskSymbol(5,25),
k * ApskSymbol(5,27),
k * ApskSymbol(5,17),
k * ApskSymbol(5,19),
k * ApskSymbol(5,23),
k * ApskSymbol(5,21),
k * ApskSymbol(5,1),
k * ApskSymbol(5,3),
k * ApskSymbol(5,7),
k * ApskSymbol(5,5),
k * ApskSymbol(5,15),
k * ApskSymbol(5,13),
k * ApskSymbol(5,9),
k * ApskSymbol(5,11),
k * ApskSymbol(15,-31),
k * ApskSymbol(15,-29),
k * ApskSymbol(15,-25),
k * ApskSymbol(15,-27),
k * ApskSymbol(15,-17),
k * ApskSymbol(15,-19),
k * ApskSymbol(15,-23),
k * ApskSymbol(15,-21),
k * ApskSymbol(15,-1),
k * ApskSymbol(15,-3),
k * ApskSymbol(15,-7),
k * ApskSymbol(15,-5),
k * ApskSymbol(15,-15),
k * ApskSymbol(15,-13),
k * ApskSymbol(15,-9),
k * ApskSymbol(15,-11),
k * ApskSymbol(15,31),
k * ApskSymbol(15,29),
k * ApskSymbol(15,25),
k * ApskSymbol(15,27),
k * ApskSymbol(15,17),
k * ApskSymbol(15,19),
k * ApskSymbol(15,23),
k * ApskSymbol(15,21),
k * ApskSymbol(15,1),
k * ApskSymbol(15,3),
k * ApskSymbol(15,7),
k * ApskSymbol(15,5),
k * ApskSymbol(15,15),
k * ApskSymbol(15,13),
k * ApskSymbol(15,9),
k * ApskSymbol(15,11),
k * ApskSymbol(13,-31),
k * ApskSymbol(13,-29),
k * ApskSymbol(13,-25),
k * ApskSymbol(13,-27),
k * ApskSymbol(13,-17),
k * ApskSymbol(13,-19),
k * ApskSymbol(13,-23),
k * ApskSymbol(13,-21),
k * ApskSymbol(13,-1),
k * ApskSymbol(13,-3),
k * ApskSymbol(13,-7),
k * ApskSymbol(13,-5),
k * ApskSymbol(13,-15),
k * ApskSymbol(13,-13),
k * ApskSymbol(13,-9),
k * ApskSymbol(13,-11),
k * ApskSymbol(13,31),
k * ApskSymbol(13,29),
k * ApskSymbol(13,25),
k * ApskSymbol(13,27),
k * ApskSymbol(13,17),
k * ApskSymbol(13,19),
k * ApskSymbol(13,23),
k * ApskSymbol(13,21),
k * ApskSymbol(13,1),
k * ApskSymbol(13,3),
k * ApskSymbol(13,7),
k * ApskSymbol(13,5),
k * ApskSymbol(13,15),
k * ApskSymbol(13,13),
k * ApskSymbol(13,9),
k * ApskSymbol(13,11),
k * ApskSymbol(9,-31),
k * ApskSymbol(9,-29),
k * ApskSymbol(9,-25),
k * ApskSymbol(9,-27),
k * ApskSymbol(9,-17),
k * ApskSymbol(9,-19),
k * ApskSymbol(9,-23),
k * ApskSymbol(9,-21),
k * ApskSymbol(9,-1),
k * ApskSymbol(9,-3),
k * ApskSymbol(9,-7),
k * ApskSymbol(9,-5),
k * ApskSymbol(9,-15),
k * ApskSymbol(9,-13),
k * ApskSymbol(9,-9),
k * ApskSymbol(9,-11),
k * ApskSymbol(9,31),
k * ApskSymbol(9,29),
k * ApskSymbol(9,25),
k * ApskSymbol(9,27),
k * ApskSymbol(9,17),
k * ApskSymbol(9,19),
k * ApskSymbol(9,23),
k * ApskSymbol(9,21),
k * ApskSymbol(9,1),
k * ApskSymbol(9,3),
k * ApskSymbol(9,7),
k * ApskSymbol(9,5),
k * ApskSymbol(9,15),
k * ApskSymbol(9,13),
k * ApskSymbol(9,9),
k * ApskSymbol(9,11),
k * ApskSymbol(11,-31),
k * ApskSymbol(11,-29),
k * ApskSymbol(11,-25),
k * ApskSymbol(11,-27),
k * ApskSymbol(11,-17),
k * ApskSymbol(11,-19),
k * ApskSymbol(11,-23),
k * ApskSymbol(11,-21),
k * ApskSymbol(11,-1),
k * ApskSymbol(11,-3),
k * ApskSymbol(11,-7),
k * ApskSymbol(11,-5),
k * ApskSymbol(11,-15),
k * ApskSymbol(11,-13),
k * ApskSymbol(11,-9),
k * ApskSymbol(11,-11),
k * ApskSymbol(11,31),
k * ApskSymbol(11,29),
k * ApskSymbol(11,25),
k * ApskSymbol(11,27),
k * ApskSymbol(11,17),
k * ApskSymbol(11,19),
k * ApskSymbol(11,23),
k * ApskSymbol(11,21),
k * ApskSymbol(11,1),
k * ApskSymbol(11,3),
k * ApskSymbol(11,7),
k * ApskSymbol(11,5),
k * ApskSymbol(11,15),
k * ApskSymbol(11,13),
k * ApskSymbol(11,9),
k * ApskSymbol(11,11)
};
const Qam1024Modulation Qam1024Modulation::singleton;
Qam1024Modulation::Qam1024Modulation() : MqamModulationBase(&constellation)
{
}
} // namespace physicallayer
} // namespace inet
|
01ff383a4cd3a5c49b0e3a5226ef7068b360c386
|
77861deda8b3046bdda221d3cb80b77e84b14523
|
/parseip4/common.cpp
|
f2196ae5dcecec36b2ccd6332e6dff087ec85f8c
|
[
"BSD-2-Clause"
] |
permissive
|
WojciechMula/toys
|
b73f09212ca19f1e76bbf2afaa5ad2efcea95175
|
6110b59de45dc1ce44388b21c6437eff49a7655c
|
refs/heads/master
| 2023-08-18T12:54:25.919406
| 2023-08-05T09:20:14
| 2023-08-05T09:20:14
| 14,905,115
| 302
| 44
|
BSD-2-Clause
| 2020-04-17T17:10:42
| 2013-12-03T20:35:37
|
C++
|
UTF-8
|
C++
| false
| false
| 912
|
cpp
|
common.cpp
|
#include "common.h"
struct errorName {
unsigned mask;
std::string name;
}
const errorName[8] = {
{errTooShort, "input too short"},
{errTooLong, "input too long"},
{errEmptyField, "field has no digits"},
{errTooBig, "field value greater than 255"},
{errWrongCharacter, "not allowed character"},
{errTooManyFields, "too many fields"},
{errTooFewFields, "too few fields"},
{errLeadingZeros, "number cannot start with 0"},
};
std::string describeErr(int err) {
switch (err) {
case 0:
return "no error";
case errInvalidInput:
return "invalid input";
}
std::string res;
for (const auto& item: errorName) {
if ((err & item.mask) != 0) {
if (!res.empty()) {
res += "/";
}
res += item.name;
}
}
return res;
}
|
8c5a938cc3252a02f545fa7ede093a30899c90b9
|
f86f01c7cb696d47fff935de60ab36a88bea7c7c
|
/Software/mex_code/ALP/ALP-4.2/Samples/Alp42Sample/AlpSample.h
|
fe855918c4dcb35d7f8dc450e3e024e20272cdec
|
[] |
no_license
|
dicarlolab/Fiberscope
|
02da70f8a6b53fee19544261b3acbd72782acf4b
|
49f389ee98cb699cf5b5acf6db105492226e8e2e
|
refs/heads/master
| 2021-08-29T17:45:28.793239
| 2017-12-14T14:09:52
| 2017-12-14T14:11:01
| 113,343,819
| 6
| 5
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,471
|
h
|
AlpSample.h
|
// AlpSample.h : main header file for the ALPSAMPLE application
//
// This is a part of the ALP application programming interface.
// Copyright (C) 2004 ViALUX GmbH
// All rights reserved.
//
#if !defined(AFX_ALPSAMPLE_H__AA820937_C345_408A_90D2_8025C7E13002__INCLUDED_)
#define AFX_ALPSAMPLE_H__AA820937_C345_408A_90D2_8025C7E13002__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CAlpSampleApp:
// See AlpSample.cpp for the implementation of this class
//
class CAlpSampleApp : public CWinApp
{
public:
CAlpSampleApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAlpSampleApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CAlpSampleApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_ALPSAMPLE_H__AA820937_C345_408A_90D2_8025C7E13002__INCLUDED_)
|
380ebef5dc758d93e150dcfe3929fed948872577
|
8784cd8d2f440fe97c4da4a30f6f86589ad37749
|
/Server/src/ClientStruct.cpp
|
929db779a38688c4a21739eba7459bd565452165
|
[] |
no_license
|
ZnHoang/SocketChat
|
604a1849b1ea5fc7c6afcfc25ecbde539950992b
|
0926b230b67c91c677dc02179d411d025b31adfb
|
refs/heads/main
| 2023-05-31T13:05:56.032871
| 2021-06-12T10:00:02
| 2021-06-12T10:00:02
| 371,892,051
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 1,271
|
cpp
|
ClientStruct.cpp
|
#include "ClientStruct.h"
ClientStruct::ClientStruct(int clitfd)
: clitFd(clitfd),
readFlag(ReadFlag::NONE),
writeFlag(WriteFlag::NONE),
evs(EPOLLONESHOT)
{
qMsg = std::make_shared<MyQueue<std::string>>();
}
const ReadFlag ClientStruct::setRead(const mRR& otFlags)
{
ulm lk(mtRead);
auto it = otFlags.find(readFlag);
auto originFlag = readFlag;
if(it != otFlags.end())
{
readFlag = it->second;
}
return originFlag;
}
const WriteFlag ClientStruct::setWrite(const mWW& otFlags)
{
ulm lk(mtWrite);
auto it = otFlags.find(writeFlag);
auto originFlag = writeFlag;
if(it != otFlags.end())
{
writeFlag = it->second;
}
return originFlag;
}
const int ClientStruct::addEvs(const int evs)
{
this->evs |= evs;
return this->evs;
}
const int ClientStruct::delEvs(const int evs)
{
this->evs &= ~evs;
return this->evs;
}
const int ClientStruct::getEvs()
{
return evs;
}
const int& ClientStruct::getClitFd()
{
return clitFd;
}
void ClientStruct::Push(const std::string&& msg)
{
qMsg.get()->Push(std::move(msg));
}
std::string ClientStruct::Pop()
{
return qMsg.get()->Pop();
}
bool ClientStruct::tryPop()
{
return qMsg.get()->tryPop();
}
|
8390efb9f0ea89c7e35ada9234bc687616f8902b
|
f90bffd8f373733fa0a1350f4c65fc607e585b09
|
/MovieStore.h
|
b7059dadf1a717a8d5b2496b0de52f79181187ea
|
[] |
no_license
|
joeghorton/HW4
|
a1aab253ba2ecefd81e1ad83a2476380b13cec21
|
92376a81872cf85531cf851f4591d5c099402e8b
|
refs/heads/master
| 2021-04-27T00:09:43.304522
| 2018-03-06T07:28:45
| 2018-03-06T07:28:45
| 123,759,081
| 0
| 0
| null | null | null | null |
UTF-8
|
C++
| false
| false
| 4,300
|
h
|
MovieStore.h
|
//
// Created by emma on 3/1/18.
//
#ifndef ASSIGNMENT4_MOVIESTORE_H
#define ASSIGNMENT4_MOVIESTORE_H
#include "RentalStore.h"
#include "MovieFactory.h"
#include "ActionHandler.h"
class MovieStore : public RentalStore {
public:
MovieFactory factory;
ActionHandler actionHandler;
// constructors
MovieStore();
~MovieStore();
bool addMovie(char category, int stock, string director, string title,
string actorFirst, string actorLast, int month, int year);
bool rentMovieFromInput(char medID, char catID, int custID, ifstream& input);
void readInInventory(ifstream& input); //read in inventory from file
void readInCustomers(ifstream& input); //read in customers from file
void readInCommands(ifstream& input); // read in commands from file
};
MovieStore::MovieStore() {
addMediaType('D');
addCategory('D', 'F');
addCategory('D', 'D');
addCategory('D', 'C');
}
MovieStore::~MovieStore() {
}
void MovieStore::readInInventory(ifstream& input) {
while (!input.eof()) {
char category = ' ';
int stock = 0, month = 0, year = 0;
string director = "", title = "", actorFirst = "", actorLast = "";
input >> category;
if (isValidCategory('D', category)) {
input.get(); // gets rid of ','
input >> stock;
input.get(); // gets rid of ','
getline(input, director, ',');
getline(input, title, ',');
if (category == 'C') {
input >> actorFirst;
input >> actorLast;
input >> month;
}
input >> year;
if (!addMovie(category, stock, director, title, actorFirst, actorLast, month, year)) {
cout << "ERROR MESSAGE 1" << endl;
}
} else { // invalid category
string temp; // gets rid of line with invalid type
getline(input, temp);
cout << "ERROR: INVALID MOVIE TYPE" << endl;
}
}
}
void MovieStore::readInCustomers(ifstream& input) {
string firstName = "", lastName = "";
int id = 0;
while (!input.eof()) {
input >> id;
input >> lastName;
input >> firstName;
addCustomer(id, firstName, lastName);
}
}
void MovieStore::readInCommands(ifstream& input) {
char type = ' ';
input >> type;
if (type == 'I') {
print();
} else {
int id = -1;
input >> id;
if (type == 'H') { // print customer history
Customer* cust = getCustomer(id);
if (cust != NULL) {
cust->displayHistory();
}
} else {
char mediaType = ' ';
char category = ' ';
input >> mediaType;
input >> category;
if (type == 'B') {
if (!rentMovieFromInput(mediaType, category, id, input)) {
cout << "ERROR: CAN'T RENT" << endl;
}
} else if (type == 'R') {
} else {
cout << "ERROR: INVALID COMMAND" << endl;
}
}
}
}
bool MovieStore::addMovie(char category, int stock, string director, string title, string actorFirst, string actorLast,
int month, int year) {
if (category == 'C') {
return addItem('D', category, factory.createClassicalMovie(director, title, actorFirst, actorLast, month, year), stock);
} else {
return addItem('D', category, factory.createMovie(category, director, title, year), stock);
}
}
bool MovieStore::rentMovieFromInput(char medID, char catID, int custID, ifstream& input) {
if (catID == 'C') {
int month = 0, year = 0;
string actorFirst = "", actorLast = "";
input >> month;
input >> year;
input >> actorFirst;
input >> actorLast;
Movie* movie = factory.createClassicalMovie("", "", actorFirst, actorLast, month, year);
if (!actionHandler.addRental(movie, custID)) {
cout << "ERROR: MOVIE NO EXIST" << endl;
}
} else if (catID == 'F') {
} else if (catID == 'D') {
} else {
cout << "ERROR: INVALID CATEGORY RENTAL" << endl;
}
}
#endif //ASSIGNMENT4_MOVIESTORE_H
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.