由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - pipe & filter 问题
相关主题
问一个generic的问题吧请问哪里能找到radixsort java code?
Comparator Accessor method for SortedSethow to use JAVA to created named pipe under windows?
error of unix redirecting command called by javaRe: Need Emergent help for Java I/O!
Process的问题ERROR!java.io.RandomAccessFile.readInt
SortedSet的问题ask a question about C
web app 每天更新数据一次高手麻烦帮帮忙。。新手学编程
请问Treeset/Treemap里面subSet(),subMap()的复杂度是多少?新手求教 BufferedReader.readLine()
TreeMap, TreeSet原来用起来这么爽help on "call a unix command in java"
相关话题的讨论汇总
话题: line话题: pipe话题: filter话题: while
进入Java版参与讨论
1 (共1页)
p****d
发帖数: 2183
1
Unix下管道很方便,可以grep 或者干点别的然后最后sort出来,
这个是pipe & filter 结构吗?
那位达人给个java 实现管道排序的例子啊?
g*****g
发帖数: 34805
2
while((line=reader.readline())!=null) {
if(line.matches(pattern) {
list.add(line);
}
}
Collections.sort(list);

【在 p****d 的大作中提到】
: Unix下管道很方便,可以grep 或者干点别的然后最后sort出来,
: 这个是pipe & filter 结构吗?
: 那位达人给个java 实现管道排序的例子啊?

p****d
发帖数: 2183
3
这就不是pipe and filter了把
Colloections做的sort已经是batch sequential的概念了, 它等所有都读完了才处理的
正常pipe & filter是处理一行就输出一行的吧
我看Unix下的sort进程好像也是和前面的管道进程同步运行的啊...
咋搞的

【在 g*****g 的大作中提到】
: while((line=reader.readline())!=null) {
: if(line.matches(pattern) {
: list.add(line);
: }
: }
: Collections.sort(list);

g*****g
发帖数: 34805
4
You must be kidding, how do you sort if you don't
read everything into memory first.

【在 p****d 的大作中提到】
: 这就不是pipe and filter了把
: Colloections做的sort已经是batch sequential的概念了, 它等所有都读完了才处理的
: 正常pipe & filter是处理一行就输出一行的吧
: 我看Unix下的sort进程好像也是和前面的管道进程同步运行的啊...
: 咋搞的

A**o
发帖数: 1550
5
magic?

【在 g*****g 的大作中提到】
: You must be kidding, how do you sort if you don't
: read everything into memory first.

p****d
发帖数: 2183
6
呵呵,我就是想知道Unix下是怎么实现的
多谢指点

【在 g*****g 的大作中提到】
: You must be kidding, how do you sort if you don't
: read everything into memory first.

m******t
发帖数: 2416
7

Well, I suppose we could use binary insert _while_ each line is read in, and
output all of them when the EOF comes.
Granted we would still have to have everything in memory at one point though
. There is no getting around that.

【在 g*****g 的大作中提到】
: You must be kidding, how do you sort if you don't
: read everything into memory first.

m******t
发帖数: 2416
8
Something like this I guess:
SortedSet set = new TreeSet();
while((line=reader.readline())!=null) {
if(line.matches(pattern) {
set.add(line);
}
}

【在 g*****g 的大作中提到】
: while((line=reader.readline())!=null) {
: if(line.matches(pattern) {
: list.add(line);
: }
: }
: Collections.sort(list);

g*****g
发帖数: 34805
9
I don't think it makes much difference.
Collections.sort is a modified mergesort with guaranteed nlog(n) performance,
You can mix IO and sorting, but performance is equivalent.


【在 m******t 的大作中提到】
: Something like this I guess:
: SortedSet set = new TreeSet();
: while((line=reader.readline())!=null) {
: if(line.matches(pattern) {
: set.add(line);
: }
: }

m******t
发帖数: 2416
10

performance,
I agree. The overall response time _might_ be better though, because the
sorting is done concurrently as the lines come in.

【在 g*****g 的大作中提到】
: I don't think it makes much difference.
: Collections.sort is a modified mergesort with guaranteed nlog(n) performance,
: You can mix IO and sorting, but performance is equivalent.
:

1 (共1页)
进入Java版参与讨论
相关主题
help on "call a unix command in java"SortedSet的问题
how to use grep/sed to remove newlines? (转载)web app 每天更新数据一次
怎么读一个文件在把读到的内容全部写到另一文件中请问Treeset/Treemap里面subSet(),subMap()的复杂度是多少?
Design optionsTreeMap, TreeSet原来用起来这么爽
问一个generic的问题吧请问哪里能找到radixsort java code?
Comparator Accessor method for SortedSethow to use JAVA to created named pipe under windows?
error of unix redirecting command called by javaRe: Need Emergent help for Java I/O!
Process的问题ERROR!java.io.RandomAccessFile.readInt
相关话题的讨论汇总
话题: line话题: pipe话题: filter话题: while