本文整理汇总了C++中setArray函数的典型用法代码示例。如果您正苦于以下问题:C++ setArray函数的具体用法?C++ setArray怎么用?C++ setArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
init_platform();
initInterrupts();
int source_word[16];
int destination_word[16];
setArray(source_word, 16, 0);
setArray(destination_word, 16, 1);
printf("Printing value before DMA transfer.\n\r");
printArray(destination_word, 16);
DMA_CONTROLLER_InitiateTransfer(XPAR_DMA_CONTROLLER_0_BASEADDR, (Xuint32) &source_word, (Xuint32) &destination_word, 4 * 10);
printf("Printing value after DMA transfer.\n\r");
printArray(destination_word, 16);
setArray(source_word, 6, 1);
DMA_CONTROLLER_InitiateTransfer(XPAR_DMA_CONTROLLER_0_BASEADDR, (Xuint32) &source_word, (Xuint32) &destination_word, 4 * 10);
printf("Printing value after 2nd DMA transfer.\n\r");
printArray(destination_word, 16);
cleanup_platform();
return 0;
}
示例2: main
int main(int argc, char const *argv[]) {
int TC;
scanf("%d", &TC);
while(TC--) {
int a, b;
scanf("%d %d", &a, &b);
int digitsA = digits(a), digitsB = digits(b);
char reversedValueA[digitsA], reversedValueB[digitsB];
setArray(reversedValueA);
setArray(reversedValueB);
reversedToString(a, digitsA, reversedValueA);
reversedToString(b, digitsB, reversedValueB);
detArray(reversedValueA);
detArray(reversedValueB);
int ra = valueOf(digitsA, reversedValueA);
int rb = valueOf(digitsB, reversedValueB);
int sum = ra + rb;
int digitsSum = digits(sum);
char reversedValue[digitsSum];
setArray(reversedValue);
reversedToString(sum, digitsSum, reversedValue);
printf("%d\n", valueOf(digitsSum, reversedValue));
}
return 0;
}
示例3: main
int main() {
int i = 0;
elem *arrayOne = (elem*)malloc(arraySize * sizeof(elem));
elem *arrayTwo = (elem*)malloc(arraySize * sizeof(elem));
resetArray(arrayOne);
setArray(arrayTwo);
initializeCount(arrayTwo);
for (i = 0; i < arraySize; i++) {
__SMACK_assert(arrayOne[i].status == RESET);
__SMACK_assert(arrayTwo[i].status == SET);
__SMACK_assert(arrayTwo[i].count == 0);
}
initializeCount(arrayOne);
setArray(arrayOne);
resetArray(arrayTwo);
for (i = 0; i < arraySize; i++) {
__SMACK_assert(arrayOne[i].count == 0);
__SMACK_assert(arrayOne[i].status == SET);
__SMACK_assert(arrayTwo[i].status == RESET);
}
free(arrayOne);
free(arrayTwo);
return 0;
}
示例4: main
int main() {
int i = 0;
int *arrayOne = (int*)malloc(MAXSIZE * sizeof(int));
int *arrayTwo = (int*)malloc(MAXSIZE * sizeof(int));
resetArray(arrayOne);
setArray(arrayTwo);
for (i = 0; i < MAXSIZE; i++) {
__SMACK_assert(arrayOne[i] == RESET);
__SMACK_assert(arrayTwo[i] == SET);
}
setArray(arrayOne);
resetArray(arrayTwo);
for (i = 0; i < MAXSIZE; i++) {
__SMACK_assert(arrayOne[i] == SET);
__SMACK_assert(arrayTwo[i] == RESET);
}
free(arrayOne);
free(arrayTwo);
return 0;
}
示例5: bitonic_subs
int bitonic_subs(int a[], int n){
//Find LIS
//LDS (longest decreasing subs)
//return max(lis[i],lds[i]-1);
int sol_lis[n];
setArray(sol_lis,n,1);
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
if(a[j] < a[i] && sol_lis[i] < sol_lis[j]+1){
sol_lis[i] = sol_lis[j]+1;
}
}
}
int sol_lds[n];
setArray(sol_lds,n,1);
for(int i = n-2; i >= 0; i--){
for(int j = n-1; j > i; j--){
if(a[j] < a[i] && sol_lds[i] < sol_lds[j]+1){
sol_lds[i] = sol_lds[j]+1;
}
}
}
int maxi = INT_MIN;
for(int i = 0; i < n; i++){
maxi = max(maxi,sol_lds[i]+sol_lis[i]-1);
}
return maxi;
}
示例6: main
int main() {
int i = 0;
elem *arrayOne;
elem *arrayTwo;
arraySize = __VERIFIER_nondet_int();
assume(arraySize > 0);
arrayOne = (elem*)malloc(arraySize * sizeof(elem));
arrayTwo = (elem*)malloc(arraySize * sizeof(elem));
resetArray(arrayOne);
setArray(arrayTwo);
initializeCount(arrayTwo);
for (i = 0; i < arraySize; i++) {
assert(arrayOne[i].status == RESET);
assert(arrayTwo[i].status == SET);
assert(arrayTwo[i].count == 0);
}
initializeCount(arrayOne);
setArray(arrayOne);
resetArray(arrayTwo);
for (i = arraySize - 1; i >= 0; i--) {
assert(arrayOne[i].count != 0 || arrayOne[i].status != SET || arrayTwo[i].status != RESET);
}
free(arrayOne);
free(arrayTwo);
return 0;
}
示例7: _finalize
void BodySystemGPU<T>::loadFile(const std::string &filename)
{
if (m_bInitialized)
_finalize();
std::vector< typename vec4<T>::Type > positions;
std::vector< typename vec4<T>::Type > velocities;
std::vector< int > ids;
int nBodies = 0;
int nFirst=0, nSecond=0, nThird=0;
read_file(positions,
velocities,
ids,
filename,
nBodies,
nFirst,
nSecond,
nThird);
_initialize(nBodies);
setArray(BODYSYSTEM_POSITION, (T *)&positions[0]);
setArray(BODYSYSTEM_VELOCITY, (T *)&velocities[0]);
}
示例8: switch
void FluidSystem::reset(FluidConfig config) //回到初始状态
{
uint s = (int)ceilf(powf((float)m_numParticles, 1.0f / 3.0f));
float jitter = m_params.particleRadius*0.01f;
switch (config)
{
default:
case CONFIG_RANDOM:
{
for (uint z = 0; z < s; z++)
{
for (uint y = 0; y < s; y++)
{
for (uint x = 0; x < s; x++)
{
uint i = (z*s * s) + (y*s) + x;
if (i < m_numParticles)
{
m_hPos[i * 4] = (3 * x) + m_params.particleRadius - 128.0f /*+ (frand()*2.0f-1.0f)*jitter*/;
m_hPos[i * 4 + 1] = (3 * y) + m_params.particleRadius - 31.0f /*+ (frand()*2.0f-1.0f)*jitter*/;
m_hPos[i * 4 + 2] = (3 * z) + m_params.particleRadius - 64.0f /*+ (frand()*2.0f-1.0f)*jitter*/;
m_hPos[i * 4 + 3] = 1.0f;
m_hVel[i * 4] = 0.0f;
m_hVel[i * 4 + 1] = 0.0f;
m_hVel[i * 4 + 2] = 0.0f;
m_hVel[i * 4 + 3] = 0.0f;
m_hDen[i] = 0.0f;
m_hPre[i] = 0.0f;
m_hColorf[i] = 0.0f;
}
}
}
}
}
break;
case CONFIG_GRID:
{
uint gridSize[3];
gridSize[0] = gridSize[1] = gridSize[2] = s;
initGrid(gridSize, m_params.particleRadius*2.0f, jitter, m_numParticles);
}
break;
}
setArray(POSITION, m_hPos, 0, m_numParticles);
setArray(VELOCITY, m_hVel, 0, m_numParticles);
setArray(DENSITY, m_hDen, 0, m_numParticles);
setArray(PRESSURE, m_hPre, 0, m_numParticles);
setArray(COLORFIELD, m_hColorf, 0, m_numParticles);
}
示例9: initFluid
void PoiseuilleFlowSystem::reset(){
elapsedTime = 0.0f;
float jitter = params.particleRadius * 0.01f;
float spacing = params.particleRadius * 2.0f;
initFluid(spacing, jitter, numParticles);
initBoundaryParticles(spacing);
setArray(POSITION, hPos, 0, numParticles);
setArray(VELOCITY, hVel, 0, numParticles);
setArray(MEASURES, hMeasures, 0, numParticles);
setArray(ACCELERATION, hAcceleration, 0, numParticles);
setArray(VELOCITYLEAPFROG, hVelLeapFrog, 0, numParticles);
}
示例10: shortestPathPQ
/*
Note:
* change priority queue implementation
*/
Graph shortestPathPQ(Graph g, Vertex v)
{
Graph mst = newGraph(g->nV);
int *dist = malloc(sizeof(int) * g->nV); // create the distance array
int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through
PQueue q = newPQueue(); // create a new priority queue
Vertex currentVertex = 0, w = 0;
int i = 0;
int total = 0;
assert(dist != NULL && pred != NULL);
// clear all the memory blocks
setArray(dist, INF, g->nV);
setArray(pred, -1, g->nV);
dist[v] = 0;
for (i = 0; i < g->nV; i++){
joinPQueue(q, i, dist[i]);
}
reorder(q, NO_UPDATE, NO_UPDATE);
while ( !isEmptyPQ(q) ){ // while priority queue is not empty
currentVertex = leavePQueue(q);
for (w = 0; w < getnV(g); w++){
if (g->wt[currentVertex][w] == NO_WEIGHT) continue;
if (g->wt[currentVertex][w] + dist[currentVertex] < dist[w]){
dist[w] = g->wt[currentVertex][w] + dist[currentVertex];
pred[w] = currentVertex;
reorder(q, w, dist[w]); // updates the priority of vertex w as well
}
}
reorder(q, NO_UPDATE, NO_UPDATE);
}
// construct the mst graph
for (i = 0; i < getnV(g); i++){
if (pred[i] != NOT_ASSIGNED){
addEdge(mst, pred[i], i);
total += dist[i];
}
}
printf("Total = %d.\n", total);
deletePQueue(q);
free(dist);
free(pred);
return mst;
}
示例11: shortestPath
Graph shortestPath(Graph g, Vertex v)
{
Graph mst = newGraph(g->nV); // create a new mst graph
Queue q = newQueue(); // create a new queue
int *visitedVertices = malloc(sizeof(Vertex) * g->nV);
int *dist = malloc(sizeof(int) * g->nV); // create the distance array
int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through
int total = 0, i = 0;
Vertex curV = 0, w = 0;
assert(visitedVertices != NULL && dist != NULL && pred != NULL);
// clear all the memory blocks
setArray(visitedVertices, UNVISITED, g->nV);
setArray(dist, INF, g->nV);
setArray(pred, -1, g->nV);
visitedVertices[v] = VISITED; // mark the starting vertex as visited
dist[v] = 0;
enQueue(q, v); // add the starting vertex to the queue
while ( !isEmptyQueue(q) ){
curV = deQueue(q); // remvoe first element from queue
for (w = 0; w < getnV(g); w++){
if (g->wt[curV][w] == NO_WEIGHT) continue;
if (dist[curV] + g->wt[curV][w] < dist[w]){ // edge relaxation
dist[w] = dist[curV] + g->wt[curV][w];
pred[w] = curV;
enQueue(q,w);
}
}
}
// add the appropriate edges
for (i = 0; i < g->nV; i++){
if (pred[i] != NOT_ASSIGNED){
addEdge(mst, pred[i], i);
total += dist[i];
}
}
deleteQueue(q);
free(dist);
free(pred);
printf("Total = %d.\n", total);
return mst;
}
示例12: Uppercase
std::vector<std::string> ConfigFile::getArray(std::string strAttribute, std::vector<std::string> listDefaults)
{
std::map<std::string, ConfigAttribute>::iterator p;
//Find the uppercase string in the map
std::string lstr = Uppercase(strAttribute);
p = m_mapConfig.find(lstr);
if (p != m_mapConfig.end() && p->second.bIsArray)
{
return p->second.listValues;
}
else
{
std::cout << "Variable " << strAttribute.c_str() << " does not exist in config file or is not an array." << std::endl;
//Store the default value in the config file
if(m_bAddDefaultsToConfig && listDefaults.size() > 0)
{
setArray(strAttribute, listDefaults);
}
return listDefaults;
}
}
示例13: clear
String::String(const String &str)
{
_length = _capacity = str._length;
_array = (char*)malloc(_length + 1);
clear();
setArray(str._array);
}
示例14: Resource
VertexArray::VertexArray(
const char *nidentifier,
void *new_array,
u32 nstride,
u32 n,
PrimitiveLayout_t layout,
AttributeUsage_t nusage
) : Resource(nidentifier, NO_PURGE, RESOURCE_VERTEX_ARRAY)
{
handle = 0;
n_attribs = 0;
stride = nstride;
indexArrayTypeSize = 0;
primitiveLayout = layout;
usage = nusage;
n_elements = n;
holds_index_array = false;
holds_array = false;
iarray = 0;
varray = 0;
has_bounds = false;
setArray(new_array, n);
}
示例15: setReferredArray
Array<scalar,index>::Array(const Array& arr)
{
if(arr.isReferred())
setReferredArray(arr.size(),arr.dataPtr(),arr.interval());
else
setArray(arr);
}