473,408 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Most efficient way of applying multiple conditional logic

..eh I was stuck thinking up a subject title for this post for a while..

So I am processing a really big file (scary big). Each record is fixed
length, I need to test conditions on certain fields in the record. At
the moment the most efficient way I've found to process the data is a
series of nested if/else statements so like below. My question is does
anyone know of a better way to process this kind of logic. I can't use a
switch statement because each condition applies to a different field
(substring) of the input record.

if (condition1)
{
reject(line);
}
else
{
if (condition2)
{
reject(line);
}
else
{
process_record(line);
}
}
}

Any thoughts appreciated.

Joe

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #1
2 1544
booksnore <sa******@plandatamgmt.com> wrote:
.eh I was stuck thinking up a subject title for this post for a while..

So I am processing a really big file (scary big). Each record is fixed
length, I need to test conditions on certain fields in the record. At
the moment the most efficient way I've found to process the data is a
series of nested if/else statements so like below. My question is does
anyone know of a better way to process this kind of logic. I can't use a
switch statement because each condition applies to a different field
(substring) of the input record.


if (condition1 ||
condition2 ||
...)
{
reject(line);
}
else
{
process_record(line);
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 23 '05 #2

This might be overkill for what you are doing, but I just happened to
use some similar logic for a program I'm writing and it might help.

This would be best suiting if you have lots of validations....

Define an interface IValidation that exposes a method bool
IsValid(string Line).

Then for each of your validations that you want to run, create a class
that implements IValidation and the IsValid method.

In your file processing piece, create an array or collection of
IValidation objects and do a foreach (IValidation val in
ValidationCollection).

This of course assumes that each IValidation is independent, meaning
that one doesn't depend on another, etc.
Anyways, just though I would share...

--Brian
Jon Skeet [C# MVP] wrote:
booksnore <sa******@plandatamgmt.com> wrote:
.eh I was stuck thinking up a subject title for this post for a while..

So I am processing a really big file (scary big). Each record is fixed
length, I need to test conditions on certain fields in the record. At
the moment the most efficient way I've found to process the data is a
series of nested if/else statements so like below. My question is does
anyone know of a better way to process this kind of logic. I can't use a
switch statement because each condition applies to a different field
(substring) of the input record.

if (condition1 ||
condition2 ||
...)
{
reject(line);
}
else
{
process_record(line);
}

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bruce | last post by:
Which of the popular templating systems (e.g. PHLib, FastTemplate, Smarty) allow you to setup conditions in your templates, for example: <-- IF Variable=value --> this HTML <-- ELSEIF...
62
by: Reinhold Birkenfeld | last post by:
Hi, after Guido's pronouncement yesterday, in one of the next versions of Python there will be a conditional expression with the following syntax: X if C else Y which is the same as today's...
15
by: Tor Erik Sønvisen | last post by:
Hi I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. regards tores
3
by: Chuck Reed | last post by:
I am working on a sales report where I show weekly sales by category for each of the 52 weeks in the year. Each record in my table/report has the 52 weeks of sales in it. I want to highlight to top...
6
by: Urs Thuermann | last post by:
Does a tool exist to apply C preprocessor expansion to a C source only partially, i.e. replace only some directives? I want to replace some #if's by their expansions, e.g. all #ifdef SOME_SYMBOL,...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
2
by: JJ48 | last post by:
Hi all, I was hoping I could get some direction for you folks on how to tackle this problem. Background: A person applying for health coverage gets assigned certain number of points which range...
21
by: py_genetic | last post by:
Hello, I'm importing large text files of data using csv. I would like to add some more auto sensing abilities. I'm considing sampling the data file and doing some fuzzy logic scoring on the...
1
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.