本文整理汇总了C++中Tuple::at方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::at方法的具体用法?C++ Tuple::at怎么用?C++ Tuple::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple::at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_profile
void VM::update_profile(STATE) {
timer::StopWatch<timer::nanoseconds> timer(metrics().machine.profile_ns);
metrics().machine.profiles++;
profile_sample_count_++;
CompiledCode* code = state->vm()->call_frame()->compiled_code;
code->machine_code()->sample_count++;
Tuple* profile = profile_.get();
if(profile->nil_p()) {
profile = Tuple::create(state, max_profile_entries_);
profile_.set(profile);
}
::qsort(reinterpret_cast<void*>(profile->field), profile->num_fields(),
sizeof(intptr_t), profile_compare);
for(native_int i = 0; i < profile->num_fields(); i++) {
if(code == profile->at(i)) return;
}
CompiledCode* pcode = try_as<CompiledCode>(profile->at(0));
if(!pcode || (pcode &&
code->machine_code()->call_count > pcode->machine_code()->call_count))
{
profile->put(state, 0, code);
min_profile_call_count_ = code->machine_code()->call_count;
}
}
示例2: calc_pressure_func
static void calc_pressure_func(int n, Tuple<double*> scalars, double* result)
{
for (int i = 0; i < n; i++)
result[i] = (num_flux.kappa - 1.) * (scalars.at(3)[i] -
(scalars.at(1)[i]*scalars.at(1)[i] + scalars.at(2)[i]*scalars.at(2)[i])/(2*scalars.at(0)[i])
);
};
示例3: redistribute
void LookupTable::redistribute(STATE, size_t size) {
size_t num = bins_->to_native();
Tuple* new_values = Tuple::create(state, size);
for(size_t i = 0; i < num; i++) {
Tuple* entry = try_as<Tuple>(values_->at(state, i));
while(entry) {
Tuple* link = try_as<Tuple>(entry->at(state, 2));
entry->put(state, 2, Qnil);
size_t bin = find_bin(key_hash(entry->at(state, 0)), size);
Tuple* slot = try_as<Tuple>(new_values->at(state, bin));
if(!slot) {
new_values->put(state, bin, entry);
} else {
entry_append(state, slot, entry);
}
entry = link;
}
}
values(state, new_values);
bins(state, Fixnum::from(size));
}
示例4: fill_opcodes
void MachineCode::fill_opcodes(STATE, CompiledCode* original) {
Tuple* ops = original->iseq()->opcodes();
int sends = 0;
int constants = 0;
for(size_t index = 0; index < total;) {
Object* val = ops->at(state, index);
if(val->nil_p()) {
opcodes[index++] = 0;
} else {
opcodes[index] = as<Fixnum>(val)->to_native();
size_t width = InstructionSequence::instruction_width(opcodes[index]);
switch(width) {
case 2:
opcodes[index + 1] = as<Fixnum>(ops->at(state, index + 1))->to_native();
break;
case 3:
opcodes[index + 1] = as<Fixnum>(ops->at(state, index + 1))->to_native();
opcodes[index + 2] = as<Fixnum>(ops->at(state, index + 2))->to_native();
break;
}
switch(opcodes[index]) {
case InstructionSequence::insn_send_method:
case InstructionSequence::insn_send_stack:
case InstructionSequence::insn_send_stack_with_block:
case InstructionSequence::insn_send_stack_with_splat:
case InstructionSequence::insn_send_super_stack_with_block:
case InstructionSequence::insn_send_super_stack_with_splat:
case InstructionSequence::insn_zsuper:
case InstructionSequence::insn_meta_send_call:
case InstructionSequence::insn_meta_send_op_plus:
case InstructionSequence::insn_meta_send_op_minus:
case InstructionSequence::insn_meta_send_op_equal:
case InstructionSequence::insn_meta_send_op_tequal:
case InstructionSequence::insn_meta_send_op_lt:
case InstructionSequence::insn_meta_send_op_gt:
case InstructionSequence::insn_meta_to_s:
case InstructionSequence::insn_check_serial:
case InstructionSequence::insn_check_serial_private:
case InstructionSequence::insn_call_custom:
sends++;
break;
case InstructionSequence::insn_push_const_fast:
case InstructionSequence::insn_find_const_fast:
constants++;
break;
}
index += width;
}
}
initialize_call_sites(state, original, sends);
initialize_constant_caches(state, original, constants);
}
示例5: test_copy_from_other_empty
void test_copy_from_other_empty() {
Tuple* tuple = Tuple::create(state, 0);
Tuple* dest = new_tuple();
dest->copy_from(state, tuple, Fixnum::from(0), Fixnum::from(0), Fixnum::from(0));
TS_ASSERT_EQUALS(Fixnum::from(1), as<Fixnum>(dest->at(state, 0)));
TS_ASSERT_EQUALS(Fixnum::from(4), as<Fixnum>(dest->at(state, 1)));
TS_ASSERT_EQUALS(Fixnum::from(9), as<Fixnum>(dest->at(state, 2)));
}
示例6: source_fn
// Source function.
void source_fn(int n, Tuple<scalar*> values, scalar* out)
{
for (int i = 0; i < n; i++)
{
out[i] = (nu[1][0] * Sf[1][0] * values.at(0)[i] +
nu[1][1] * Sf[1][1] * values.at(1)[i] +
nu[1][2] * Sf[1][2] * values.at(2)[i] +
nu[1][3] * Sf[1][3] * values.at(3)[i]);
}
}
示例7: is_rescue_target
bool CompiledMethod::is_rescue_target(STATE, int ip) {
Tuple* table = exceptions();
if(table->nil_p()) return false;
for(size_t i = 0; i < table->num_fields(); i++) {
Tuple* entry = as<Tuple>(table->at(state, i));
if(as<Fixnum>(entry->at(state, 2))->to_native() == ip) return true;
}
return false;
}
示例8: test_delete_inplace
void test_delete_inplace() {
Tuple *tuple = new_tuple();
tuple->put(state, 1, Qnil);
Integer *count = tuple->delete_inplace(state, Fixnum::from(0), Fixnum::from(3), Qnil);
TS_ASSERT_EQUALS(1, count->to_native());
TS_ASSERT_EQUALS(Fixnum::from(1), as<Fixnum>(tuple->at(state, 0)));
TS_ASSERT_EQUALS(Fixnum::from(9), as<Fixnum>(tuple->at(state, 1)));
TS_ASSERT_EQUALS(Qnil, tuple->at(state, 2));
}
示例9: can_join
bool Relation::can_join(Tuple t1, Tuple t2, std::vector<std::pair<int, int>> common_attributes) {
bool can_join = false;
for (auto pair : common_attributes) {
if ( t1.at(pair.first) == t2.at(pair.second) ) {
can_join = true;
}
else {
can_join = false;
return can_join;
}
}
return can_join;
}
示例10: priority
/** @todo Should we queue thread? Probably unnecessary. --rue */
void Thread::priority(STATE, Fixnum* new_priority) {
/* This gets somewhat ugly to avoid existing lists. */
if(new_priority->to_native() < 0) {
Exception::argument_error(state, "Thread priority must be non-negative!");
}
Tuple* scheduled = state->globals.scheduled_threads.get();
std::size_t desired = new_priority->to_ulong();
std::size_t existing = scheduled->num_fields();
if(desired >= existing) {
Tuple* replacement = Tuple::create(state, (desired + 1));
replacement->copy_from(state, scheduled, Fixnum::from(0),
Fixnum::from(scheduled->num_fields()),
Fixnum::from(0));
for(std::size_t i = existing - 1; i <= desired; ++i) {
if(replacement->at(state, i)->nil_p()) {
replacement->put(state, i, List::create(state));
}
}
state->globals.scheduled_threads.set(replacement);
scheduled = replacement;
}
priority_ = new_priority;
}
示例11: update_cached_rarray
/* We were in Ruby-land and we are heading to C-land. In Ruby-land, we
* may have updated the existing Array elements, appended new elements,
* or shifted off elements. We account for this when updating the C
* structure contents.
*
* We are potentially writing into a C structure that exists and that
* may have been changed in C-land. It is possible for C code to change
* both the len and ptr values of an RArray. We DO NOT EVER encourage
* doing this, but we must account for it. The C code may also merely
* change the contents of the array pointed to by ptr. Updating that
* array with the current elements in the Ruby Array is the purpose of
* this code.
*/
void update_cached_rarray(NativeMethodEnvironment* env, Handle* handle) {
if(handle->is_rarray()) {
Array* array = c_as<Array>(handle->object());
Tuple* tuple = array->tuple();
RArray* rarray = handle->as_rarray(env);
native_int size = tuple->num_fields();
native_int start = array->start()->to_native();
native_int num = 0;
if(rarray->ptr != rarray->dmwmb) {
// This is a very bad C extension. Assume len is valid
// and do not change its value.
num = rarray->len;
} else {
env->shared().capi_ds_lock().lock();
if(rarray->aux.capa < size) {
delete[] rarray->dmwmb;
rarray->dmwmb = rarray->ptr = new VALUE[size];
rarray->aux.capa = size;
}
num = rarray->aux.capa;
rarray->len = array->size();
env->shared().capi_ds_lock().unlock();
}
for(native_int i = 0, j = start; i < num && j < size; i++, j++) {
rarray->ptr[i] = env->get_handle(tuple->at(j));
}
}
}
示例12: nth_capture
Object* MatchData::nth_capture(STATE, native_int which) {
if(region_->num_fields() <= which) return cNil;
Tuple* sub = try_as<Tuple>(region_->at(state, which));
if(!sub) return cNil;
Fixnum* beg = try_as<Fixnum>(sub->at(state, 0));
Fixnum* fin = try_as<Fixnum>(sub->at(state, 1));
native_int b = beg->to_native();
native_int f = fin->to_native();
native_int max = source_->byte_size();
if(!beg || !fin ||
f > max ||
b < 0) {
return cNil;
}
const char* str = (char*)source_->byte_address();
native_int sz = f - b;
if(sz > max) sz = max;
String* string = String::create(state, str + b, sz);
string->encoding(state, source_->encoding());
return string;
}
示例13: indent
void Tuple::Info::show_simple(STATE, Object* self, int level) {
Tuple* tup = as<Tuple>(self);
native_int size = tup->num_fields();
native_int stop = size < 6 ? size : 6;
if(size == 0) {
class_info(state, self, true);
return;
}
class_info(state, self);
std::cout << ": " << size << std::endl;
++level;
for(native_int i = 0; i < stop; i++) {
indent(level);
Object* obj = tup->at(state, i);
if(Tuple* t = try_as<Tuple>(obj)) {
class_info(state, self);
std::cout << ": " << t->num_fields() << ">" << std::endl;
} else {
obj->show_simple(state, level);
}
}
if(tup->num_fields() > stop) ellipsis(level);
close_body(level);
}
示例14: find_and_activate_thread
bool VM::find_and_activate_thread() {
Tuple* scheduled = globals.scheduled_threads.get();
for(std::size_t i = scheduled->num_fields() - 1; i > 0; i--) {
List* list = as<List>(scheduled->at(this, i));
Thread* thread = try_as<Thread>(list->shift(this));
while(thread) {
thread->queued(this, Qfalse);
/** @todo Should probably try to prevent dead threads here.. */
if(thread->alive() == Qfalse) {
thread = try_as<Thread>(list->shift(this));
continue;
}
if(thread->sleep() == Qtrue) {
thread = try_as<Thread>(list->shift(this));
continue;
}
activate_thread(thread);
return true;
}
}
return false;
}
示例15: find
/* lookuptable_find returns Qundef if there is not entry
* referenced by 'key' in the LookupTable. This is useful
* to distinguish x = {} from x = {:a => nil} and is used
* in cpu.c in e.g. cpu_const_get_in_context.
*/
Object* LookupTable::find(STATE, Object* key) {
Tuple* entry = find_entry(state, key);
if(entry) {
return entry->at(state, 1);
}
return Qundef;
}