473,626 Members | 3,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1554
booksnore <sa******@pland atamgmt.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.co m>
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
ValidationColle ction).

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******@pland atamgmt.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
3522
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 Variable=value --> this HTML <-- ENDIF Variable=value --> --Bruce
62
3274
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 (Y, X)
15
2324
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
2307
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 five weeks of sales for each category by using a conditonal format to highlight these top five weeks. I've been trying to find a way to do this but have not been sucessful looking through many books on Access and in reading the user groups. If...
6
2425
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, but keep all other #ifdef OTHER_SYMBOL and all #include directives. urs
6
2067
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 DeviceManager which is only interested in CD/DVD devices. I want to get the list of CD/DVD devices and "be informed when a disc inserted into a device". I am developing this on Linux. So, I used HAL API and read some system (actually /proc) files to gather...
2
1327
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 from 1 - around 200. Based on the points and their age group, we decide what level of coverage (5 levels) they get. Each level has a maximum point allowed. The number of points per plan and level is very random. The only sequence is that Level 1 is...
21
1999
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 attributes (colls in a data base/ csv file, eg. height weight income etc.) to determine the most efficient 'type' to convert the attribute coll into for further processing and efficient storage... Example row from sampled file data: , ....]
1
3880
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 a single folder called 'All Files' Do we spread them out and copy them to multiple folders like Folder 000 - Copy files from 0 to 1000 Folder 001 - Copy files from 1000 to 2000 Folder 002 - Copy files from 2000 to 2999
0
8199
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.