本文整理汇总了C++中SymbolSet::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolSet::insert方法的具体用法?C++ SymbolSet::insert怎么用?C++ SymbolSet::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolSet
的用法示例。
在下文中一共展示了SymbolSet::insert方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filter_not_grouped
SEXP filter_not_grouped( DataFrame df, List args, const DataDots& dots){
CharacterVector names = df.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
if( dots.single_env() ){
Environment env = dots.envir(0) ;
// a, b, c -> a & b & c
Shield<SEXP> call( and_calls( args, set ) ) ;
// replace the symbols that are in the data frame by vectors from the data frame
// and evaluate the expression
CallProxy proxy( (SEXP)call, df, env ) ;
LogicalVector test = proxy.eval() ;
check_filter_result(test, df.nrows());
DataFrame res = subset( df, test, df.names(), classes_not_grouped() ) ;
return res ;
} else {
int nargs = args.size() ;
CallProxy first_proxy(args[0], df, dots.envir(0) ) ;
LogicalVector test = first_proxy.eval() ;
check_filter_result(test, df.nrows());
for( int i=1; i<nargs; i++){
LogicalVector test2 = CallProxy(args[i], df, dots.envir(i) ).eval() ;
combine_and(test, test2) ;
}
DataFrame res = subset( df, test, df.names(), classes_not_grouped() ) ;
return res ;
}
}
示例2: filter_grouped_single_env
DataFrame filter_grouped_single_env( const GroupedDataFrame& gdf, const List& args, const Environment& env){
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
// a, b, c -> a & b & c
Call call( and_calls( args, set ) ) ;
int nrows = data.nrows() ;
LogicalVector test = no_init(nrows);
LogicalVector g_test ;
GroupedCallProxy call_proxy( call, gdf, env ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = call_proxy.get( indices );
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = g_test[j] ;
}
}
DataFrame res = subset( data, test, names, classes_grouped() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例3: filter_grouped_multiple_env
// version of grouped filter when contributions to ... come from several environment
DataFrame filter_grouped_multiple_env( const GroupedDataFrame& gdf, const List& args, const DataDots& dots){
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_install( names[i] ) ) ;
}
int nrows = data.nrows() ;
LogicalVector test(nrows, TRUE);
LogicalVector g_test ;
for( int k=0; k<args.size(); k++){
Call call( (SEXP)args[k] ) ;
GroupedCallProxy call_proxy( call, gdf, dots.envir(k) ) ;
int ngroups = gdf.ngroups() ;
GroupedDataFrame::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = call_proxy.get( indices );
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = test[ indices[j] ] & g_test[j] ;
}
}
}
DataFrame res = subset( data, test, names, classes_grouped() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例4:
SymbolSet
CTNode::childSymbols (void) const
{
SymbolSet symbols;
for (CTChilds::const_iterator chIt = childs_.begin();
chIt != childs_.end(); ++ chIt) {
symbols.insert ((*chIt)->symbol());
}
return symbols;
}
示例5: DoDirProp
bool Object_FTC_Manager::DoDirProp(Environment &env, SymbolSet &symbols)
{
Signal &sig = GetSignal();
if (!Object::DoDirProp(env, symbols)) return false;
#if 0
symbols.insert(Gura_Symbol(x));
symbols.insert(Gura_Symbol(y));
#endif
return true;
}
示例6: filter_not_grouped
DataFrame filter_not_grouped( DataFrame df, const LazyDots& dots){
CharacterVector names = df.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_installChar( names[i] ) ) ;
}
if( dots.single_env() ){
Environment env = dots[0].env() ;
// a, b, c -> a & b & c
Shield<SEXP> call( and_calls( dots, set, env ) ) ;
// replace the symbols that are in the data frame by vectors from the data frame
// and evaluate the expression
CallProxy proxy( (SEXP)call, df, env ) ;
LogicalVector test = check_filter_logical_result(proxy.eval()) ;
if( test.size() == 1){
if( test[0] == TRUE ){
return df ;
} else {
return empty_subset(df, df.names(), classes_not_grouped()) ;
}
} else {
check_filter_result(test, df.nrows());
return subset(df, test, classes_not_grouped() ) ;
}
} else {
int nargs = dots.size() ;
Call call(dots[0].expr());
CallProxy first_proxy(call, df, dots[0].env() ) ;
LogicalVector test = check_filter_logical_result(first_proxy.eval()) ;
if( test.size() == 1 ) {
if( !test[0] ){
return empty_subset(df, df.names(), classes_not_grouped() ) ;
}
} else {
check_filter_result(test, df.nrows());
}
for( int i=1; i<nargs; i++){
Rcpp::checkUserInterrupt() ;
Call call( dots[i].expr() ) ;
CallProxy proxy(call, df, dots[i].env() ) ;
LogicalVector test2 = check_filter_logical_result(proxy.eval()) ;
if( combine_and(test, test2) ){
return empty_subset(df, df.names(), classes_not_grouped() ) ;
}
}
DataFrame res = subset( df, test, classes_not_grouped() ) ;
return res ;
}
}
示例7:
// ****************************************************************************
// Method: ConfiguratingSet::GetShiftSymbols
//
// Purpose:
// Get the set of symbols which can be shifted in this set.
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// ****************************************************************************
SymbolSet
ConfiguratingSet::GetShiftSymbols()
{
SymbolSet shiftsymbols;
for (size_t i=0; i<items.size(); i++)
{
if (! items[i].CanReduce())
shiftsymbols.insert(items[i].GetNextSymbol());
}
return shiftsymbols;
}
示例8: allLookaheadsOf
SymbolSet allLookaheadsOf(const Item & item, const Grammar & grammar)
{
SymbolList followingSymbols = item.rule.remainingSymbolsAfter(item.dottedSymbol);
followingSymbols.push_back({ Symbol::Type::TERMINAL, "" });
SymbolSet allLookaheads;
for(auto & lookahead : item.lookaheads)
{
followingSymbols.back() = lookahead;
auto first = grammar.first(followingSymbols);
allLookaheads.insert(first.begin(), first.end());
}
return allLookaheads;
}
示例9: filter_grouped_multiple_env
DataFrame filter_grouped_multiple_env( const Data& gdf, const LazyDots& dots){
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_installChar( names[i] ) ) ;
}
int nrows = data.nrows() ;
LogicalVector test(nrows, TRUE);
LogicalVector g_test ;
for( int k=0; k<dots.size(); k++){
Rcpp::checkUserInterrupt() ;
const Lazy& lazy = dots[k] ;
Call call( lazy.expr() ) ;
GroupedCallProxy<Data, Subsets> call_proxy( call, gdf, lazy.env() ) ;
int ngroups = gdf.ngroups() ;
typename Data::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = check_filter_logical_result(call_proxy.get( indices ));
if( g_test.size() == 1 ){
if( g_test[0] != TRUE ){
for( int j=0; j<chunk_size; j++){
test[indices[j]] = FALSE ;
}
}
} else {
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
if( g_test[j] != TRUE ){
test[ indices[j] ] = FALSE ;
}
}
}
}
}
DataFrame res = subset( data, test, names, classes_grouped<Data>() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例10:
// ****************************************************************************
// Method: Sequence::GetFirstSet
//
// Purpose:
// Get the first set of this sequence.
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// ****************************************************************************
SymbolSet
Sequence::GetFirstSet(const vector<const Rule*> &rules) const
{
SymbolSet first;
for (size_t i=0; i<symbols.size(); i++)
{
if (symbols[i]->IsTerminal())
{
first.insert(symbols[i]);
break;
}
first.merge( symbols[i]->GetFirstSet(rules) );
if (! symbols[i]->IsNullable(rules))
break;
}
return first;
}
示例11: filter_grouped_single_env
DataFrame filter_grouped_single_env( const Data& gdf, const LazyDots& dots){
typedef GroupedCallProxy<Data, Subsets> Proxy ;
Environment env = dots[0].env() ;
const DataFrame& data = gdf.data() ;
CharacterVector names = data.names() ;
SymbolSet set ;
for( int i=0; i<names.size(); i++){
set.insert( Rf_installChar( names[i] ) ) ;
}
// a, b, c -> a & b & c
Call call( and_calls( dots, set, env ) ) ;
int nrows = data.nrows() ;
LogicalVector test(nrows, TRUE);
LogicalVector g_test ;
Proxy call_proxy( call, gdf, env ) ;
int ngroups = gdf.ngroups() ;
typename Data::group_iterator git = gdf.group_begin() ;
for( int i=0; i<ngroups; i++, ++git){
SlicingIndex indices = *git ;
int chunk_size = indices.size() ;
g_test = check_filter_logical_result( call_proxy.get( indices ) ) ;
if( g_test.size() == 1 ){
int val = g_test[0] == TRUE ;
for( int j=0; j<chunk_size; j++){
test[ indices[j] ] = val ;
}
} else {
check_filter_result(g_test, chunk_size ) ;
for( int j=0; j<chunk_size; j++){
if( g_test[j] != TRUE ) test[ indices[j] ] = FALSE ;
}
}
}
DataFrame res = subset( data, test, names, classes_grouped<Data>() ) ;
res.attr( "vars") = data.attr("vars") ;
return res ;
}
示例12:
// ****************************************************************************
// Method: Symbol::GetFirstSet
//
// Purpose:
// Gets the first set for any production of this symbol.
// For terminals, the first set is the identity operation.
//
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// ****************************************************************************
SymbolSet
Symbol::GetFirstSet(const vector<const Rule*> &rules) const
{
SymbolSet first;
if (type == Terminal)
{
first.insert(this);
}
else
{
for (size_t i=0; i<rules.size(); i++)
{
if (rules[i]->GetLHS() == this &&
// Try to avoid infinite recursion -- this should be improved!
(rules[i]->GetRHS().Empty() || rules[i]->GetRHS()[0] != this))
{
first.merge( rules[i]->GetRHS().GetFirstSet(rules) );
}
}
}
return first;
}
示例13: slice_not_grouped
SEXP slice_not_grouped(const DataFrame& df, const LazyDots& dots) {
CharacterVector names = df.names();
SymbolSet set;
for (int i=0; i<names.size(); i++) {
set.insert(Rf_installChar(names[i]));
}
const Lazy& lazy = dots[0];
Call call(lazy.expr());
CallProxy proxy(call, df, lazy.env());
int nr = df.nrows();
IntegerVector test = check_filter_integer_result(proxy.eval());
int n = test.size();
// count the positive and negatives
CountIndices counter(nr, test);
// just positives -> one based subset
if (counter.is_positive()) {
int n_pos = counter.get_n_positive();
std::vector<int> idx(n_pos);
int j=0;
for (int i=0; i<n_pos; i++) {
while (test[j] > nr || test[j] == NA_INTEGER) j++;
idx[i] = test[j++] - 1;
}
return subset(df, idx, df.names(), classes_not_grouped());
}
// special case where only NA
if (counter.get_n_negative() == 0) {
std::vector<int> indices;
DataFrame res = subset(df, indices, df.names(), classes_not_grouped());
return res;
}
// just negatives (out of range is dealt with early in CountIndices).
std::set<int> drop;
for (int i=0; i<n; i++) {
if (test[i] != NA_INTEGER)
drop.insert(-test[i]);
}
int n_drop = drop.size();
std::vector<int> indices(nr - n_drop);
std::set<int>::const_iterator drop_it = drop.begin();
int i = 0, j = 0;
while (drop_it != drop.end()) {
int next_drop = *drop_it - 1;
while (j < next_drop) {
indices[i++] = j++;
}
j++;
++drop_it;
}
while (i < nr - n_drop) {
indices[i++] = j++;
}
DataFrame res = subset(df, indices, df.names(), classes_not_grouped());
return res;
}
示例14: slice_grouped
SEXP slice_grouped(GroupedDataFrame gdf, const LazyDots& dots) {
typedef GroupedCallProxy<GroupedDataFrame, LazyGroupedSubsets> Proxy;
const DataFrame& data = gdf.data();
const Lazy& lazy = dots[0];
Environment env = lazy.env();
SymbolVector names = data.names();
SymbolSet set;
for (int i=0; i<names.size(); i++) {
set.insert(names[i].get_symbol());
}
// we already checked that we have only one expression
Call call(lazy.expr());
std::vector<int> indx;
indx.reserve(1000);
IntegerVector g_test;
Proxy call_proxy(call, gdf, env);
int ngroups = gdf.ngroups();
GroupedDataFrame::group_iterator git = gdf.group_begin();
for (int i=0; i<ngroups; i++, ++git) {
const SlicingIndex& indices = *git;
int nr = indices.size();
g_test = check_filter_integer_result(call_proxy.get(indices));
CountIndices counter(indices.size(), g_test);
if (counter.is_positive()) {
// positive indexing
int ntest = g_test.size();
for (int j=0; j<ntest; j++) {
if (!(g_test[j] > nr || g_test[j] == NA_INTEGER)) {
indx.push_back(indices[g_test[j]-1]);
}
}
} else if (counter.get_n_negative() != 0) {
// negative indexing
std::set<int> drop;
int n = g_test.size();
for (int j=0; j<n; j++) {
if (g_test[j] != NA_INTEGER)
drop.insert(-g_test[j]);
}
int n_drop = drop.size();
std::set<int>::const_iterator drop_it = drop.begin();
int k = 0, j = 0;
while (drop_it != drop.end()) {
int next_drop = *drop_it - 1;
while (j < next_drop) {
indx.push_back(indices[j++]);
k++;
}
j++;
++drop_it;
}
while (k < nr - n_drop) {
indx.push_back(indices[j++]);
k++;
}
}
}
DataFrame res = subset(data, indx, names, classes_grouped<GroupedDataFrame>());
set_vars(res, get_vars(data));
strip_index(res);
return GroupedDataFrame(res).data();
}