Re: find if any memers of a set are in another set (blank line finder)?
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Jul 18, 2002
- 404 views
Thanks Matt, I'm gonna have to try your method one to see what it does, I don't get it on just reading it (ditto the one liner variation). I'd considered your last "test each character in the line against the white_space set" method, but had just assumed it would be slower than some kind of "test whole set against whole set" method. Dan ----- Original Message ----- From: "Matthew Lewis" <matthewwalkerlewis at YAHOO.COM> To: "EUforum" <EUforum at topica.com> Sent: Thursday, July 18, 2002 5:43 AM Subject: RE: find if any memers of a set are in another set (blank line finder)? > > > > -----Original Message----- > > From: Dan Moyer [mailto:DANIELMOYER at prodigy.net] > > > I want to be able to discern whether a sequence (a line of > > text) is "empty" > > (ie, has *only* spaces or tabs or CR or any combination of > > those), or if it > > has *any* alpha/num/punctuation content at all. In other > > words,a "blank" > > line finder. And it needs to function as quickly as possible. > > > > I thought there might be a spiffy way similar to how: > > > > w = {1, 2, 3} = {1, 2, 4} gives: w={1,1,0} > > You could do it this way: > > -- your line is in sequence line > constant white_space = { ' ', '\t', '\r', '\n' } > sequence l > > l = repeat(0,length(line)) > for i = 1 to length( white_space ) do > l += ( line = white_space[i] ) > end for > > if find( 0, l ) then > -- something else in there > end if > > Rewritten a-la Carl's one liners: > not_blank = find(0, (line = ' ') + (line = '\t') + (line = '\r') + (line = > '\n') ) > > Functionally, but not necessarily speedwise equivalent: > not_blank = find(0, (line = ' ') or (line = '\t') or (line = '\r') or (line > = '\n') ) > > > w = {1, 2, 3} or {1, 2, 4} gives me: w= {1,1,1}, which I > > don't understand. > > (I'm thinking it means that neither 3 nor 4 are zero.) > > Here's why: > w = { 1 or 1, 2 or 2, 3 or 4 } = {1,1,1} > > > So, is there some way to find if any member of a given set is found in > > another set, or some different, good (fast) way to find "blank" lines? > > I often use this method: > > for i = 1 to length(line) do > if not find(line[i], white_space) then > -- found something else! > end if > end for > > This would most likely be faster if the first non-whitespace character were > toward the beginning of the line. You might also get different results > depending on the length of the lines to be tested. While the first method > is cool because it uses slick sequence math, I suspect that the last version > will be the fastest for your purposes. > > Matt Lewis > >