我正在用C++构建一个聚类算法,但是我不能很好地处理OOP和变化的变量状态(成员数据).对于某种复杂性的算法,我发现这是我开发的障碍.
所以,我正在考虑将编程语言改为其中一种函数语言:Ocaml或F#.除了必须改变我对如何进行编程的思维方式之外,我还需要澄清一些问题.在C++中,我使用双端队列来滑动数据中的时间窗口.一段时间后,将删除最旧的数据并附加较新的数据.尚未过时的数据仍保留在双端队列中.
另一个更苛刻的任务是比较每个对象之一的属性.每个对象都是来自特定时间段的数据.如果我在某个时间窗口有一千个数据对象,我需要将每个数据对象比较为无或二十或三十,具体取决于.并且该比较对象的某些属性可能会因此比较而发生变化.在C++中,我使用引用完成所有操作,这意味着我访问内存中的对象,它们永远不会被复制,因此算法全速运行(据我所知的C++).
我一直在阅读有关函数式编程的知识,我得到的想法是每个函数执行一些操作并且原始数据(输入)不会改变.这意味着该语言复制数据结构并执行所需的转换.如果是这样,使用函数式编程将大大延迟算法的执行.它是否正确?如果没有,即,如果有快速的方法来执行数据转换,是否可以告诉我如何操作?一个很小的例子会很棒.
我希望有一些设施.我读过Ocaml和F#都用于研究和科学项目.
我想用增量值替换一些文本.考虑文件xx:
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
Run Code Online (Sandbox Code Playgroud)
和sed命令:
for n in seq 3;do sed -e 's/<RecordID>\d/<RecordID>'`echo $n`'/' xx; done
Run Code Online (Sandbox Code Playgroud)
该echo $n命令没有得到增加.
尝试过:
n=1; sed -e 's/<RecordID>/<RecordID>'`echo $n ;let n=$n+1`'/g' xx
Run Code Online (Sandbox Code Playgroud)
但没有成功.
仅考虑sed(没有awk或perl)我如何将RecordID字段递增,如下所示:
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
<RecordID>2</RecordID>
<outro>dfdfd</outro>
<RecordID>3</RecordID>
<outro>dfdfd</outro>
Run Code Online (Sandbox Code Playgroud) 我正在尝试编译下面的两个文件,但是从编译器收到一条错误消息:gcc 4.3.3(Linux)
该错误位于使用以下方式签署的行中:LINE WITH ERROR
我做错了什么,我该怎么改呢?
路易斯...............................
$ g++ -c b.h b.cpp
b.cpp: In function 'void calcularDesempPop(std::vector<Individuo, std::allocator<Individuo> >&)':
b.cpp:19: error: name lookup of 'iter' changed for new ISO 'for' scoping
b.cpp:17: error: using obsolete binding at 'iter'
Run Code Online (Sandbox Code Playgroud)
...............................文件:b.cpp
#include <iostream>
#include <algorithm>
#include "desempenho.h"
using std::cout;
using std::endl;
struct Individuo {
vector<double> vec;
double desempenho;
};
void calcularDesempPop(vector<Individuo>& pop) {
for (vector<Individuo>::iterator iter = pop.begin();
iter != pop.end(); ++iter);//LINE WITH ERROR
iter->desempenho = calcularDesempenho(iter->vec);
cout << endl;
}
Run Code Online (Sandbox Code Playgroud)
...............................文件:bh …
我正在尝试使用pqxx编译一个非常简单的程序(不做任何操作的样本),但不能这样做.这是'程序':
$ cat xx.cpp
#include <pqxx/pqxx>
using namespace pqxx;
int main()
{
connection conn("dbname=dout1");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我以前尝试用C++编译的命令:
g++ -I /usr/local/include/ -L /usr/local/lib/ -l pqxx -I /opt/postgres_home/include/ -L /opt/postgres_home/lib/ -lpq xx.cpp
Run Code Online (Sandbox Code Playgroud)
消息返回:
/tmp/cc18wMEy.o: In function `pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
xx.cpp:(.text._ZN4pqxx14connect_directC1ERKSs[pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x1f): undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
xx.cpp:(.text._ZN4pqxx14connect_directC1ERKSs[pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x2a): undefined reference to `vtable for pqxx::connect_direct'
/tmp/cc18wMEy.o: In function `pqxx::connect_direct::~connect_direct()':
xx.cpp:(.text._ZN4pqxx14connect_directD1Ev[pqxx::connect_direct::~connect_direct()]+0x13): undefined reference to `vtable for pqxx::connect_direct'
xx.cpp:(.text._ZN4pqxx14connect_directD1Ev[pqxx::connect_direct::~connect_direct()]+0x1f): undefined reference to `pqxx::connectionpolicy::~connectionpolicy()' …Run Code Online (Sandbox Code Playgroud) 正如标题所说,我已经建立了一个set的pair,我需要通过有序值double value(秒):
set<pair<unsigned int, double> > s
我正在编写一些将转换为 HTML 的文本,作为一个长页面。
无法弄清楚如何像在 HTML 中一样使用 链接到部分#some-id,以便用户在单击它时会向上或向下浏览网页
<h2 id="some-id">Section A</h2>
<p>Lot's of lines</p>
<a href="#some-id">Go to section</a>
Run Code Online (Sandbox Code Playgroud) 请考虑下表'mmm':
select * from mmm;
Run Code Online (Sandbox Code Playgroud)
输出:
+-------+-------+------+
| texto | value | n |
+-------+-------+------+
| aaa | 10 | 1 |
| aab | 10 | 1 |
| aaa | 11 | 1 |
| aab | 11 | 1 |
| aaa | 10 | 2 |
+-------+-------+------+
Run Code Online (Sandbox Code Playgroud)
命令:
select a.*, '--', b.*
from mmm a
left join mmm b on (a.n=b.n)
where a.value < b.value
and a.texto ='aaa'
and b.texto='aab';
Run Code Online (Sandbox Code Playgroud)
收益:
+-------+-------+------+----+-------+-------+------+
| texto | value …Run Code Online (Sandbox Code Playgroud)