由买买提看人间百态

topics

全部话题 - 话题: iter
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
D**u
发帖数: 288
1
来自主题: DataSciences版 - pig能做iterative的问题吗?
Pig itself has no support for iteration, but if you really want to use Pig,
you can embed the pig script into a python (jython) program to do it
iteratively.
Check this for example:
http://thedatachef.blogspot.com/2013/11/linear-regression-with-
After all, this is not best practice since for every iteration a M/R job is
spanned, and that is 2 sec wasted, and usually your algorithm runs with
hundreds of iteration. So, just use Spark. Spark now support both Scala and
Python pretty much equally wel... 阅读全帖
a**x
发帖数: 154
2
来自主题: JobHunting版 - 问个stl iterator的问题
in this case the compiler has no idea about vector::iterator is a inner
class name or a static var in vector. so you need to use
typename vector::iterator vit;
to define a iterator
m*****g
发帖数: 226
3
来自主题: JobHunting版 - 问个stl的iterator问题
stl container use iterators instead of pointers.
however, what if i want to use a pointer to pointers, can i do it with
iterators? how?
for example, with normal pointers, i can do
int *A, *B;
int **P;
if(...) *P = A;
else *P=B;
how to do this with iterators?
thx
z**********g
发帖数: 209
4
来自主题: JobHunting版 - google和iterator
问个google的编程题
collapsingIterator for vector>
发现google很喜欢然人编iterator啊
我还有两道题是
Write an iterator over multiple collections.
Implement an Array iterator.
都是google的, 请问这种题要写到什么程度哪?
s******e
发帖数: 108
5
Design an iterator for a collection of collections. The iterator should hide
the nesting, allowing you to iterate all of the elements belonging to all
of the collections as if you were working with a single collection.
For Example:
a={{1,2,3},4,{},{5,6,{7,{},{8}}},}.
The result of calling 8 time next() should be:
1,2,3,4,5,6,7,8.
q********c
发帖数: 1774
6
来自主题: JobHunting版 - binary tree的in-order iterator怎么写?
你这个不是iterator, 而是traversal, 两个是不一样的.Iterator class 要有一个
current state 指向 current node, 每次执行 advance/++ (C++) 或者next(Java)操
作,返回下一个node. 所以inorder iterator 实际上就是找到下一个inorder node.
E*******0
发帖数: 465
7
讨论个iterator, reverse_iterator, const iterator and const reverse_iterator
之间转换。
l*****a
发帖数: 14598
8
来自主题: JobHunting版 - 讨论一道题:deep iterator
http://www.mitbbs.com/article/JobHunting/32345677_3.html
我的理解是value可以还是Map
差不多,我用了一个Stack or List 来存储各层的iterator
r*********n
发帖数: 4553
9
来自主题: JobHunting版 - bst中序遍历c++ class iterator
要写一个真正的C++ iterator不容易,对于bst,bidirectional iterator应该就够了。
//T is the type of tree node value
template class BSTIterator: public std::iterator iterator_tag, T> {
//....
public:
//...
BSTIterator& operator++();
BSTIterator opterator++(int);
BSTIterator& operator--();
BSTIterator operator--(int);
T& operator*();
bool operator==(const BSTIterator&);
bool operator!=(const BSTIterator&);
};
至少把上面几个关键的operator overload之后才差不多吧。
r*********n
发帖数: 4553
10
根据以前板上的讨论,可以用stack of iterator 来实现,取it = stack.top(),
如果 it == map.end()的时候就把it pop out,当遇到新的一个nested map,就把其
iterator放到stack里面去。最后当stack为空的时候,就iteration结束了。
s*******n
发帖数: 305
11
之前用array+list实现hashtable的时候写过一个相应的iterator, 这方面实在是基础
很差..., 最后是在hashtable 定义了一个方法, 把所有数据都放到一个
arraylist里面(类似于楼主的traversal()), 然后再由Iterator get 到, 怎么都感
觉象是个伪Iterator...
要是面试碰到楼主这个题, 肯定跪了, 楼主的解法很精妙, mark.
祝楼主好运, 拿到onsite
f**********s
发帖数: 115
12
iterator的顺序是什么样的?in order吗?
考虑用iterative in order traversal的原理, 用stack来遍历一遍, 每次pop的时候
把结果存到一个list里, 然后iterate那个list就是你想要的结果。
b***e
发帖数: 1419
13
来自主题: JobHunting版 - 一道Iterator题
这个基本上就是每个线程保持一个normal iterator的栈。栈顶的iterator结束了就pop
out。否则就用栈顶的iterator继续next。
A*****o
发帖数: 284
14
来自主题: JobHunting版 - 请教 Iterator 一题
Implement Iterator接口,但是增加一个功能,peek()返回next()的值,但是不能
移动pointer。 constructor已经指定,就是 PeekIterator(Iterator iter)
请问这个Java怎么搞?谢谢
f**********t
发帖数: 1001
15
来自主题: JobHunting版 - 实现vector的iterator,template问题
实现了vector的iterator,包括Next(), hasNext(), peek()等功能。
但是一旦用template写又卡住了。
这里vector::iterator it; 会出错:missing ";" before identifier "it"
感觉是个编译问题,但不知怎么fix. 求指教。多谢!=)
template class VectorIterator {
vector vec_;
vector::iterator it;
public:
VectorIterator(vector &vec) {
vec_ = vec;
it = vec_.begin();
}
bool hasNext() {
return it != vec_.end();
}
T next() {
if (!hasNext()) {
throw exception("End of vector");
... 阅读全帖
w****a
发帖数: 710
16
感觉我做法好像跟你有点不一样。比如说输入,
那个nested array我的想法大概是类似这样的:
比如输入为,{0, {1, 2}, 3 ,{4, {5, 6}}}
vector nested;
nested.push_back(any((int)0));

vector element1 = {any((int)1), any((int)2)};
nested.push_back(any(element1));

nested.push_back(any(3));

vector element3 = {any(4)};
vector element3_1 = {any(5),any(6)};
nested.push_back(any(element3_1));
迭代器:
NestedIterator it(nested);
while (it.has_next()) {
cout << it.get_next() << " ";
}
我想法是不用stl的iterator。好像跟你思路不太一样... 阅读全帖
y****z
发帖数: 52
17
来自主题: JobHunting版 - LC的BST iterator到底要考察什么?
楼主 你理解错题意了
题意不是让你把所有的节点遍历出来 是要你写一个iterator() iterator只会返回下
一个节点 当存在无数个节点时 你那样写根本就没有结果 而iterator可以返回节点
z****e
发帖数: 2024
18
来自主题: CS版 - 请教how to implement iterator
don't use STL iterator style if you are new.
it has many advanced designs far beyond a regular coder's research.
for a linked list, usually you define a iterator as a friend class, the
private member usually is the reference of the head node of the linked list. you need to overload ++, --, *, ->, =, etc. that's it.
in STL, you need to at least understand what is "iterator traits" in order to carry on. so if you are new, and prepare for interview only, don't bother to read STL source.
a*********r
发帖数: 7
19
来自主题: Programming版 - c++ iterator 弱问
#include
using namespace std;
class A {
public:
void begin() const;
private:
map elements;
map::iterator iter;
};
void A::begin() const {
iter = elements.begin();
~~~~~~~~~~~~~~~这里编译的时候报错,显示no match for operator=
这个该怎么fix呢?
}
int main() {
A a;
a.begin();
return 0;
}
t****t
发帖数: 6806
20
来自主题: Programming版 - STL iterator的疑问
input iterator: read-only pointer
output iterator: write-only pointer
forward iterator: you can increase by 1, but not decrease
bidirectional: you can increase/decrease by 1
random: you can +/- by any amount
1-pass: you can't go back; you can't even write twice to same slot
about your example: regular operation doesn't involve memory management. so
if you use std::copy, you must have the space already allocated. if not, you
are actually doing write+allocate, which corresponds to push_back() or
i
c**a
发帖数: 316
21
来自主题: Programming版 - Pointer to iterator?
怎么把 pointer 转化成 iterator 呢?
string s("life sucks.");
string::size_type pos = 3;
string::iterator it = &s[pos]; // error!
string::iterator it = s.begin() + 3; //not pretty....
d****n
发帖数: 130
22
来自主题: Programming版 - vector::iterator不对
我定义了function template, 有个参数是iterator:
template
void fun(vector::iterator it)
{
}
但是编译通不过,说vector::iterator不是一个TYPE.
g****r
发帖数: 35
23
假定
C
是预定义的 template class
用 list 保存一组 C 指针
std::list*> myList;
如何设计一个 template 函数,在其中采用 iterator 访问 myList 的成员?
template
void f(T& t)
{
std::list*> pos = myList.begin();
std::list*>::iterator pos; // This line give me
error
while (pos != myList.end())
{
(*pos).... blah blah
++pos;
}
}
编译器对 iterator 的定义行报错,如下:
error: parse error before `;' token
替换为
std::_List_iterator*> pos;
在 iMac 上
d*******n
发帖数: 524
24
I know this is doable:
template
void f(Iterator first, Iterator last );
But then later when you call f, you need to write
f>(vi.begin(), vi.end());
However, for those functions in the stl algorithm, no template parameter is
needed when calling them. How is that implemented?
t****t
发帖数: 6806
25
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
等等,你这答案根本不对。iterator is not smart pointer. at all.
which iterator is smart pointer (that can manage resource) in STL? none.
and design pattern is not "想让它作甚,就作甚". in addition, the design patt
ern iterator is not what asked here.
recommended book: effective STL...

现在还有标准的争论么? 我这里大致的用一下,就原则性错误了?
z****e
发帖数: 2024
26
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
我说过了,iterator 是 smart pointer 这个不是我先发明的,是书上说的,好几本都
出现过这种说法。
这是一个说法,至于什么才是 “smart pointer ”,就是文字游戏和标注之争了。
我完全同意iterator在STL里边不能resource management.但是不带表不能设计一种具有此工能iterator啊。
我思过去了,不敢和二位恩师争。
我错了!

patt
X****r
发帖数: 3557
27
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
除非所有的iterator都是smart pointer,你说iterator是smart pointer
就是错误的。某些iterator是smart pointer不改变这一点。

现在还
有标准的争论么? 我这里大致的用一下,就原则性错误了?
g*********s
发帖数: 1782
28
来自主题: Programming版 - stl iterator has "NULL" like const?
It's a long story.
I'm designing a LRU cache. For each char ch being accessed, there's an int
typed time stamp. For example, ('a', 3) means @ time 3 we access char 'a'.
The cache must support fast operations of the following:
query(char ch)
insert(char key, int time_stamp)
get_earliest_time(int time&)
get_latest_time(int time&).
I use a vector X and a sorted doubly linked list Y. The sorted linked list
would keep the latest time stamp of each char, and the vector would keep the
address of each e... 阅读全帖
j*****u
发帖数: 186
29
下面程序来自于essential C++ 3.6节,给定一个数组,输出比某个数小的所以元素。
main函数中用了back_inserter,按道理是不是应该include iterator头文件和
using std::back_inserter? 但是为什么把这两句注释掉程序也能跑呢?谢谢。
===================================================================
#include
#include
#include
#include
#include
//#include
using std::vector;
using std::cout;
using std::endl;
using std::less;
//using std::back_inserter;
template 阅读全帖
j*****u
发帖数: 186
30
下面程序来自于essential C++ 3.6节,给定一个数组,输出比某个数小的所以元素。
main函数中用了back_inserter,按道理是不是应该include iterator头文件和
using std::back_inserter? 但是为什么把这两句注释掉程序也能跑呢?谢谢。
===================================================================
#include
#include
#include
#include
#include
//#include
using std::vector;
using std::cout;
using std::endl;
using std::less;
//using std::back_inserter;
template 阅读全帖
f**h
发帖数: 1149
31
iterative detection and decoding 也就是那种利用turbo原理 让soft message在
soft detector 和 soft decoder之间做多个iteration然后再做decision。不知道这种
结构的receiver的实际应用复杂度到底有多高,我只的是用ASIC 或者FPGA等的硬件实
现。我看文献
虽然这种结构比那种non-turbo 也就是没有iterative的那种结构peformance要好很多
,但是好像工业界一般并不采用这种turbo的结构。我对硬件不是很了解。想知道这个
这种结构在实现上主要有什么问题?是复杂度高很多还是delay太多??有人来说说吗
??
g*********n
发帖数: 119
32
来自主题: DataSciences版 - pig能做iterative的问题吗?
大家就事论事,还是不要伤和气的好。
再想想草鱼最初提的问题,其实他更关注的是iterative processing,而不是他举的
matrix manipulation的例子。如果要考虑iterative processing的不是数组这么low
level的operation,而是数据流的iterative processing,Pig还是可以胜任的,不过
是重复性的insert,update, delete, 这些基本操作。数组并不是最好的例子。
h******i
发帖数: 21077
33
ITER是啥意思?
搞IT的人么?
s******y
发帖数: 28562
34
这件事情,貌似主要是国内的人搞分裂。
国内做这个核聚变的主要有两个山头,一个是中科院/中科大,另外一个山头我不点名
,行内人自己明白。
我以前听到的谣言就是另外的那个山头极端的看不起中科院的土鳖/孙子(他们直接用
了“孙子”这个词)。ITER这个事情,就是那个高大上山头觉得外国的月亮比较圆所以
嚷嚷着要加入欧洲那个而把国内的那个直接放弃。不过中科院的人也不是吃素的,争吵
半天之后上面糊稀泥决定两头都上,大头投资放在欧洲那边,中科院那个给他们一点小
钱继续允许他们小打小闹。结果后来的事情大家都知道了。
k***e
发帖数: 556
35
来自主题: JobHunting版 - 问个stl iterator的问题
template
void testTemp(vector& v) {
vector::iterator vit;
vit = v.begin( );
}
如上所示,我想用定义一个iterator与参数T有关,再做些操作,
结果有错。哪位能指点一下!谢谢!
B*******1
发帖数: 2454
36
是不是用一个iterator,里面根据每个collection的类型再call相应对象的iterator去
打印出数。
d********w
发帖数: 363
37
来自主题: JobHunting版 - [google面试]iterator访问
给出一个二维vector,实现 flatten类
class flatten implements iterator{
public flatten(vector> a);
boolean hasNext();
iterator next();
}
可以用size求出所有的元素多少,但好像也不必,还要考虑到一些特殊case,比如里面
的vector大小为空。大家能写个bug free很简洁的么,谢谢
p*****2
发帖数: 21240
38
来自主题: JobHunting版 - [google面试]iterator访问

还真是。刚才查了一下,说vector不支持iterator, 还是enumeration, 所以就是考察
从enumeratoion 转到iterator?
b********8
发帖数: 69
39
来自主题: JobHunting版 - [google面试]iterator访问
世界真的很小,我也面到这道,实现flatten iterator of iterator,可惜当时没做好
,挂了。。
w****x
发帖数: 2483
40

一般是不是只有tail recursion 才比较好做成iteration, 也不是所有的recursion都
可能做成iteration的吧
p*****2
发帖数: 21240
41
来自主题: JobHunting版 - iterator 实现 如何 peek(),pop()?
class Iterator[T](arr:Array[T]){
private[this] var pos=0
def peek()={
if(pos }

def pop()={
if(pos }

def reset(){
pos=0
}
}
object test2 extends App {
val arr=Array(1,2,3,4,5)
val it=new Iterator(arr)
println(it.peek())
println(it.pop())
println(it.peek())
println(it.pop())
println(it.peek())
println(it.pop())

}
j*****y
发帖数: 1071
42
来自主题: JobHunting版 - iterator 实现 如何 peek(),pop()?
二爷这个iterator 和 stack 好像是一样的?
class iterator == class stack ?
c********t
发帖数: 5706
43
来自主题: JobHunting版 - iterator 实现 如何 peek(),pop()?
同意,这道题里面pop和iterator next 感觉是一样的,没必要实现。
不过你用array来实现,感觉不合题意吧。我觉得extend Iterator,overwrite next
hasNext, remove, add pop and peek methods是正解。
s**x
发帖数: 7506
44
来自主题: JobHunting版 - 讨论一道题:deep iterator

share 一下 more detail 吧。 我也想知道至少一种解法。
iterator C++ 那种
for( itr=data.begin(); itr < data.end(); itr++) {process (*iterator); }
还是很麻烦的,我当时只知道这个, 所以直接跪了。
while(data.hasNext()) { process data.getNext(); } 貌似简单很多。
f*******n
发帖数: 12623
45
理论上你的计算机就是一个很大的iterative程序。所以所有你的计算机能做的东西,
都能以iterative做的。
u*****o
发帖数: 1224
46
弱问LZ,面试官说一定要用iterator了是吗? in order traversal用threaded trees
不是更好吗,不用stack. 还是他就说要考察iterator的使用?
n****e
发帖数: 678
47
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
仔细看了一下code,
有几个问题:
1, Collection只能遍历一边,第二次遍历就出错了。
2, 这里没有iterator的 implementation。 如何用c++实现iterator
n****e
发帖数: 678
48
来自主题: JobHunting版 - 小弟求问LinkedIn那道Deep Iterator的题
仔细看了一下code,
有几个问题:
1, Collection只能遍历一边,第二次遍历就出错了。
2, 这里没有iterator的 implementation。 如何用c++实现iterator
l*n
发帖数: 529
49
来自主题: JobHunting版 - 一道Iterator题
没有要求remove,相当于immutable,不用管多线程吧?
或者是想要你的Iterator被共享?那么在实现iterator的数据结构里进行synchronized吧
h**o
发帖数: 548
50
象这种题目的iterative解法一般有什么套路那?
好像三种树(pre, in, postorder)的iterative traversal法都套不上啊?
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)