The most efficient way to search a large String

Hi All,
2 Quick Questions
QUESTION 1:
I have about 50 String keywords -- I would like to use to search a big String object (between 300-3000 characters)
Is the most efficient way to search it for my keywords like this ?
if(myBigString.indexOf("string1")!=1 || myBigString.indexOf("string2")!=1 || myBigString.indexOf("string1")!=1 and so on for 50 strings.)
System.out.println("it was found");
QUESTION 2:
Can someone help me out with a regular expression search of phone number in the format NNN-NNN-NNNN
I would like it to return all instances of that pattern found on the page .
I have done regular expressions, in javascript in vbscript but I have never done regular expressions in java.
Thanks

Answer 2:
If you have the option of using Java 1.4, have a look at the new regular expressions library... whose package name I forget :-/ There have been articles published on it, both at JavaWorld and IBM's developerWorks.
If you can't use Java 1.4, have a look at the jakarta regular expression projects, of which I think there are two (ORO and Perl-like, off the top of my head)
http://jakarta.apache.org/
Answer 1:
If you have n search terms, and are searching through a string of length l (the haystack, as in looking for a needle in a haystack), then searching for each term in turn will take time O(n*l). In particular, it will take longer the more terms you add (in a linear fashion, assuming the haystack stays the same length)
If this is sufficient, then do it! The simplest solution is (almost) always the easiest to maintain.
An alternative is to create a finite state machine that defines the search terms (Or multiple parallel finite state machines would probably be easier). You can then loop over the haystack string a single time to find every search term at once. Such an algorithm will take O(n*k) time to construct the finite state information (given an average search term length of k), and then O(l) for the search. For a large number of search terms, or a very large search string, this method will be faster than the naive method.
One example of a state-search for strings is the Boyer-Moore algorithm.
http://www-igm.univ-mlv.fr/~lecroq/string/tunedbm.html
Regards, and have fun,
-Troy

Similar Messages

  • What is the most efficient way of converting relatively large program to pervious version?

    I am trying to convert 8.5 labview program to 8.2 version.  When I do that it creates many more subfolders with VIs that are not converted.
    What is the best way to do this?  I tried the mass compile but converting the high level  program creates many folders that links to other areas?
    Am I missing anything?
    Thanks for any help.
    Chetna 

    Hi Chetna,
    How are you confirming that the VIs saved in the sub-folders after conversion have not been converted to a previous version? 
    If you open the VI at the top of the hierarchy and 'Save for Previous Version...' it saves the open VI and all it's depencies for the chosen version. The reason you see all the sub-folders is because the relative path between VIs is maintained.
    This KnowledgeBase article: Can I Save VIs in My Current LabVIEW for Use in a Previous Version? describes this process.
    There is also a Community Example: Programmatically Save VIs for Previous Version that could also save time if you have a lot of VIs to convert.
    I hope this helps!
    Tanya V
    National Instruments
    LabVIEW Platform Product Support Engineer

  • What is the most efficient way of passing large amounts of data through several subVIs?

    I am acquiring data at a rate of once every 30mS. This data is sorted into clusters with relevant information being grouped together. These clusters are then added to a queue. I have a cluster of queue references to keep track of all the queues. I pass this cluster around to the various sub VIs where I dequeue the data. Is this the most efficient way of moving the data around? I could also use "Obtain Queue" and the queue name to create the reference whenever I need it.
    Or would it be more efficient to create one large cluster which I pass around? Then I can use unbundle by index to pick off the values I need. This large cluster can have all the values individually or it co
    uld be composed of the previously mentioned clusters (ie. a large cluster of clusters).

    > I am acquiring data at a rate of once every 30mS. This data is sorted
    > into clusters with relevant information being grouped together. These
    > clusters are then added to a queue. I have a cluster of queue
    > references to keep track of all the queues. I pass this cluster
    > around to the various sub VIs where I dequeue the data. Is this the
    > most efficient way of moving the data around? I could also use
    > "Obtain Queue" and the queue name to create the reference whenever I
    > need it.
    > Or would it be more efficient to create one large cluster which I pass
    > around? Then I can use unbundle by index to pick off the values I
    > need. This large cluster can have all the values individually or it
    > could be composed of the previously mentioned clusters (i
    e. a large
    > cluster of clusters).
    It sounds pretty good the way you have it. In general, you want to sort
    these into groups that make sense to you. Then if there is a
    performance problem, you can arrange them so that it is a bit better for
    the computer, but lets face it, our performance counts too. Anyway,
    this generally means a smallish number of groups with a reasonable
    number of references or objects in them. If you need to group them into
    one to pass somewhere, bundle the clusters together and unbundle them on
    the other side to minimize the connectors needed. Since the references
    are four bytes, you don't need to worry about the performance of moving
    these around anyway.
    Greg McKaskle

  • I am giving my old MacBook Air to my granddaughter.  What is the most efficient way to erase all the data on it?

    I am giving my old MacBook Air to my granddaughter.  What is the most efficient way to erase the data?

    You have two options.....
    One is to do a clean reinstall of your OS - if you still have the USB installer that came with your Macbook Air...
    The second option is to create a new user (your granddaugher's name).....Deauthorize your Macbook Air from your Itunes and Appstore.....
    Restart your Macbook after you've created your granddaughter's user name, login under your granddaughter's username and delete your username.
    Search your Macbook for your old files and delete them.....
    Good luck...

  • What is the most efficient way to compare two Lists?

    List A{itemId,itemName} [1,xyz] [9,iyk] [4,iuo] .......
    List B{itemId,item price} [2,999] [9,888] [1, 444].......
    Assume A will be a much larger list than B
    I am trying to find all the items with same itemiId. what would be the most efficient way to do that?
    Thanks!

    Tinkerbell. wrote:
    BigDaddyLoveHandles wrote:
    You wrote:
    Can we assume that an itemId only occurs once in each list? You're the one making claims and assumptions, not me.No in #4 I asked the OP to verify an assumption.An assumption that couldn't possibly be true. Why are you wasting our time?

  • What is the most efficient way to have full access to the front panel on RT Labview?

    I have a RT machine that needs to do its job and also port the front panel to an external machine over the network. What is the most efficient way to do it? Using as little of the RT time as possible but providing full functionality to the RT front panel.
    So far I have been using it directly from Labview - running the VI on a remote (RT) and have the front panel on local Labview (WINDOWS). I know I can do it with also through WWW (not very happy with that though).
    LV2009 SP1.
    Thanks

    Running a compiled executable on the RT target, rather than running it within the development environment, is probably slightly more efficient but limits you to the web interface.  If you're running within the LabVIEW environment, I doubt there's a noticeable difference in efficiency from the RT perspective between the web server and the LabVIEW front panel, although that's mostly a guess (I would expect the RT system to send identical data in each case, once the front panel is loaded).  Those are your only options in modern LabVIEW versions.  In LabVIEW 7.1 you could build an executable that acted as the front panel for an RT system, but that feature does not exist in recent versions.  However, a quick search turned up this document with code to approximately duplicate that behavior, perhaps it will work for you?

  • What's the most efficient way to serve a file from a servlet?

    I have a servlet that does various different things depending on the needs. Sometimes it dynamically generates content, and sometimes all it does is send a file out, with no alteration.
    What is the most efficient way to just send a file?
    One option:
    OutputStream os = response.getOutputStream();
    InputStream is = new FileInputStream(...)
    (send all the bytes from is to os, the regular way using a buffer)Another option is to say:
    RequestDispatcher rd = response.getRequestDispatcher(fileName);
    rd.forward();Any other options? What's the prefered way of doing this?
    I know the rule of "don't optimize too early" but this is a situation where we need to get the maximum amount of files served with the hardware we have, and it's going to be a lot of static files, so efficiency is important.
    Thanks

    Ok, that's what I thought. It would be nice if there were a "response.sendStream(InputStream input)" method in the ServletResponse class. Even nicer would be a sendFile or sendChannel or something. This is probably a common usage and it's a place where the container has many opportunities for optimization. For example, it could call the operating systems send_file kernel call so the entire transfer would be done directly from the disk controller to the ether card (on systems that support that).
    For now I'll just do my own buffered copy.

  • What is the most efficient way to convert a static site to a responsive site using Dreamweaver?

    I need to convert an old site made in Dreamweaver to be responsive to any monitor size. What is the most efficient way to do this?

    Depending on what you have to work with and how it was coded, it might be doable and then again not.  Suffice it to say, there are no magic buttons that will do this for you. Also consider that mobile & tablet users interact differently with their web devices. So your navigation & forms must be finger friendly.  Also images & content must make mobile users happy without killing their dataplans.  There's a lot of planning that goes into making a good Responsive Web site.
    Nancy O.

  • What is the most efficient way to turn an array of 16 bit unsigned integers into an ASCII string such that...?

    What is the most efficient way to turn a one dimensional array of 16 bit unsigned integers into an ASCII string such that the low byte of the integer is first, then the high byte, then two bytes of hex "00" (that is to say, two null characters in a row)?
    My method seems somewhat ad hoc. I take the number, split it, then interleave it with 2 arrays of 4095 bytes. Easy enough, but it depends on all of these files being exactly 16380 bytes, which theoretically they should be.
    The size of the array is known. However, if it were not, what would be the best method?
    (And yes, I am trying to read in a file format from another program)

    My method:
    Attachments:
    word_array_to_weird_string.vi ‏18 KB

  • What is the most efficient way to post several stories to multiple html pages

    What is the most efficient way to post five stories to multiple html pages?
    Currently they are all html files saved in DW with some divs sharing content and other divs are unique.
    I've experimented with saving stories as library items and dropping into other html but wondered if there is a more efficient or dynamic process.

    Server-Side Includes.
    http://forums.adobe.com/message/2112460#2112460
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Moving content from iMovie to iMovie - what's the most efficient way?

    If I edit and create movies in iMovie08 on one iMac and I want to transfer the content to iMovie08 another iMac 200 miles away , what's the most efficient way? I prefer not to burn DVDs, because I want to do further work on the movies on the second iMac's iMovie (so I can share them with iTunes and sync them with Apple TV).

    >PDPageAddCosContents(destPage, PDPageGetCosContents(srcPage));
    Does this method (PDPageGetCosContent) exist? It would be easy enough
    to create, but I don't see it in the document.
    More seriously, I have a vague memory that it is a Really Bad Thing to
    share the same Contents objects between multiple pages. Maybe
    something to do with page deletion, can't remember.
    >PDPageAddCosResource(destPage, PDPageGetCosResources(srcPage));
    These two methods are not symmetric, and PDPageAddCosResource doesn't
    work that way, sadly...
    Aandi Inston

  • What's the most efficient way to transfer to personal domain?

    I've been using the cumbersome .Mac address and have spent a lot of time optimizing the site, having also purchased a domain name (which I'll switch to), which is currently masked and forwarded. So what's the most smooth way of using the personal domain without losing all the strides I've made to get bumped up in the rankings? Thanks in advance for your suggestions. www.RedCottageInc.com (that's my future personal domain!)

    I'm saying that you give Google the .Mac URL to get to your sitemap but use the registered domain name for normal access.
    You are promoting your site with www.RedCottageInc.com but, because it is masked, Google needs your web.mac address to access the verification file and the sitemap so that it can spider your site.
    You normally upload your sitemap as "sitemap.xml". You can test its accessibility by entering
    http://web.mac.com/username/WebSiteName/Sitemap.xml in your browser.
    Google needs this URL to get to the sitemap - visitors will use www.RedCottageInc.com.
    Google wants to get to the verification file and the sitemap but your website visitors don't.
    I guess all this is confusing if you haven't done it before and I don't know that I am explaining it very well. The best way to get it is to go through all the steps of creating the verification file and sitemap, uploading them to your site folder and adding and verifying in your Google control panel.
    Here are the relevant Google pages...
    Guidelines...
    http://www.google.com/support/webmasters/bin/answer.py?answer=35769
    Add URL to Google...
    http://www.google.com/addurl/?continue=/addurl
    Verification file....
    http://www.google.com/support/webmasters/bin/answer.py?answer=35658&query=html+f ile&topic=&type=
    Sitemap...
    http://www.google.com/support/webmasters/bin/answer.py?answer=34657&ctx=sibling

  • What is the most efficient way to pass LV data to a dll?

    For efficiency, this question primarily becomes important when passing large arrays, structures containing large arrays, or generally, any large block of data to a dll.
    The way the dll setup appears and the .c file it create for the dll call, it appears that labVIEW directly passes data in whatever native passing format LV requires without copying the actual data if you select the "Adapt to Type" as the "Type" option. If I pass an array, for example, the .c file contains the type definition of a labVIEW array, i.e., (size,data), and depending whether I select handle or handle pointer, the data passed is either a handle or handle pointer to the array. Likewise, if I pass a LV structure, the .c file will con
    tain the typedef to the structure and the data passed is either a pointer, or pointer to a pointer. These are, I believe, labVIEW native types and do not require copying.
    On the other hand if an array is passed as an array type, then it is converted to a C array that requires LV to copy the array on both sides of the call.
    I further assume all structures can be passed to the memory manager to be manipulated, although I'm actually not sure that you could resize an array pointer in the dll. That seems a bit dubious, but then I guess upon return LV could query the memory manager to determine the array pointer size.
    That�s how I would think things work. If not, could someone please correct me?
    Kind regards,
    Eric

    Eric,
    Let me tell you something about me too...
    I've been working with LabVIEW for (just) 4 years. That is, 40 hours a week
    professionally, 10 hours a week privatelly. I've started with LV4, and went
    through all versions and revisions until 6.0.2 (6.1 will come soon, but
    first I have to finish some major projects.
    During this time I've been working on lots of interfaces with the windows
    OS. Some 'dll' things I've worked on: OpenGL interface, MSXML driver,
    keyboard hooks, mouse hooks, GDI interfacing, calling LV dll's from
    assembler, calling assembler dll's from LV, creating threads, using serial
    interrupts, etc. I'm now (also) working on a way to automatically generate
    documentation (much more then the 'export VI stings') from a VI. This
    requires 'under the hood' knowledge about how VI's work.
    When I had to make a fast routine for a project one time, I choose
    assembler, because I had this knowledge. Also, I wanted to use pure SIMD
    opperations. The operation had to modify an array of DBL's. The SIMD uses
    the same format (IEEE 754, I think), so it was easy. But when it came to
    testing, it appeard that the routine only paid off if the routine was 'long'
    enough. The routine was n*O^2, where n was a parameter. When the array was
    large, and n small, the overhead of copiing the array to modifiable memory
    was relativelly large, and the LV routine was faster.
    When I get a pointer to a LV array, I can use this pointer to modify the
    data in the array. This can (I think) only be done if LV copied this data,
    just like LV is doing when a wire is split to be modified.
    It might be that this copiing can be prevented, e.g. by using other data
    types, or fiddling with threads and reentrance... If you want to optimally
    benefit from dll's I'd look for a way to keep the data in the dll space, or
    pass it once at initialisation. You could use CreateHeap, HeapAlloc,
    AllocGlobal, and other functions. You can use these functions in LV, or in
    the dll. Once you have a pointer to the (one and only) data space, you can
    use this to pass to the dll functions.
    I think LV does not show the memory in question in the profiler, but I'm not
    sure.
    Using the "Adapt to type" option might just result in a internal convertion
    during 'compile' time, and might be exactly the same as doing it yourself.
    Perhaps you can share a bit about the application you are making, or at
    least why you need the speed you are seeking?
    Regards,
    Wiebe.
    "Eric6756" wrote in message
    news:50650000000500000025C60000-1042324653000@exch​ange.ni.com...
    Greg,
    There are two relevant documents which are distributed with labVIEW,
    in labVIEW 6i, (hey, I'll get around to upgrading), the first is
    titled, "Using External Code in LabVIEW", the second is application
    note 154, "LabVIEW Data Formats".
    Actually, a statement Wiebe@air made on my previous question regarding
    dll calls, "Do dll calls monopolize the calling thead?" provoked this
    line of questions. Based on other things he has said, I gather he is
    also using dlls. So as long as we're here let me ask the next
    question...
    If labVIEW must make a copy of the passed data, does it show up as
    additional memory blocks in the vi profiler? In other words, can you
    use the profiler to infer what labVIEW is doing, or as you put it,
    infer whether there is a clever passing method available?
    As a personal note Greg:
    First, as a one time engineering student and teaching assistant, I
    don't recall hearing or using the terms "magical", or "clever". Nor I
    might add, do I find them in print elsewhere in technical journals.
    While I don't mind NI marketing in their marketing documents, used
    here in this mostly educational forum, they strike me as arrogant,
    and/or pompous.
    I like NI's products because they work and are reliable. I doubt it
    has anything to do with magic, has somewhat more to do with being
    clever, but is mostly due to the dogmatic persistence of your
    engineers. I rather doubt any of them adjoin the term "magical" or
    even "clever" to their solutions. I believe the term "best" is
    generally accepted with the qualifier "I've or we've found". At
    least, that has been my engineering experience.
    Second, many of my questions I can sort out on my own, but I figure as
    long as your willing to answer the questions, then your answers are
    generally available to others. The problem is that one question seems
    to lead to another and specific information gets buried in a rather
    lengthy discourse. When I come here with a specific question, it
    would be nice to find it asked and answered specifically rather than
    buried in the obscurity of some other question. As such, at some
    point in these discussions it might be appropriate to reframe a
    question and put at the top. In my opinion, that decision is
    primarily yours as you have a better feel for the redundancy of
    questions asked and/or your answers.
    Anyway, the next question I'm posting at the top is, "Do the handles
    passed to a dll have to be locked down to insure other threads don't
    move the data?"
    Thanks,
    Kind Regards,
    Eric

  • SQL query with multiple tables - what is the most efficient way?

    Hello I am learning PL/SQL. I have a simple procedure where I need to find number of employees and departments per location as per user input of location_id.
    I have 3 Tables:
    LOCATIONS
    location_id (pk)
    location_name
    DEPARTMENTS
    department_id (pk)
    location_id (fk)
    department_name
    EMPLOYEES
    employee_id (pk)
    department_id (fk)
    employee_name
    1 Location can have 0-MANY Departments
    1 Employee has 1 Department
    Here is the query I came up with for PL/SQL procedure:
    /*Ecount, Dcount are NUMBER variables */
    SELECT SUM (EmployeeCount), COUNT(DepartmentNumber)
         INTO Ecount, Dcount
         FROM     
         (SELECT COUNT(employee_id) EmployeeCount, department_id DepartmentNumber
              FROM employees
              GROUP BY department_id
              HAVING department_id IN
                        (SELECT department_id
                        FROM departments
                        WHERE location_id = userInput));
    I do get the correct result, but I am just wondering if my query is on the right track and if there is a more "efficient" way of doing this.
    Thanks in advance for helping a newbie out.

    Hi,
    Welcome to the forum!
    Something like this will be more efficient:
    SELECT    COUNT (employee_id)               AS ECount
    ,       COUNT (DISTINCT department_id)     AS DCount
    FROM       employees
    WHERE       department_id IN (     SELECT     department_id
                        FROM      departments
                        WHERE      location_id = :userInput
    ;You should also try a join instead of the IN subquery.
    For efficiency, do only the things you need to do.
    For example, you don't need a count of employees in each department, so don't compute one. That means you won't need the in-line view, so don't have one.
    You don't need PL/SQL for this job, so don't use PL/SQL if you don't have to. (I realize this question was out of context, so you may have good reasons for doing this in PL/SQL.)
    Do all filtering as early as possible. Don't waste effort computing things that won't be used .
    A particular example of this is: Never use a HAVING clause when you can use a WHERE clause. What's the difference between a WHERE clause and a HAVING clause? The WHERE clause is applied before aggregate functions are computed, and the HAVING clause is applied after; there's no other difference. Therefore, if the HAVING clause isn't referencing an aggregate function, it could be done in a WHERE clause instead.

  • What is the most efficient way to run internet explorer on a mac?

    I have to use I.E. for school along with Outlook.  I run windows for mac and am looking for the cheapest and least invasive way to do so.

    CSS731 wrote:
    Specifically I cannot attach files such as students grades or send requests to our photocopy center.  I works great on a pc but won't work on a mac.  Most at my institution thumb their noses at macs and I have been told directly they will not support mac or OSX.  I have tried using firefox but have been told by my colleagues that IE is the only browser that works.
    What you are running into is unfortunately rather common in business, education, and government. What happened is that your school computerized their operations in the late 1990s to early 2000s, when Internet Explorer on Windows XP was the most common web browser. Websites were coded to take advantage of technologies that are unique to IE. Once all these institutions and businesses finished their work, they thought they were done and they moved on.
    But in the time since then, the world changed around them. The Web moved towards "standards compliance," which means writing web sites for the CSS3 and HTML5 standards. Not for old Microsoft-only Internet Explorer features. If a web site is standards compliant, it will work on any browser that is also standards compliant. That would include every popular browser today: Apple Safari, Mozilla Firefox, and Google Chrome. (As well as the latest Internet Explorer for Windows, which is much better than it used to be.)
    Standards compliance was a wonderful revolution, because it meant we could use any browser. It also paved the way for the iOS and Android mobile device boom, since they need to use mobile web browsers and those are not Internet Explorer.
    The big problem is that your institution, like many others in education, business, and government, either doesn't want to upgrade their systems or doesn't have the budget. The system they built in 1996 or 2002 is being maintained, but it isn't being modernized. Therefore, it is not standards compliant. That's why it doesn't work with Firefox or Safari.
    I am sure that both you and they have noticed that they have fallen behind, because it's very easy to show this. If you go to any modern web site...Facebook, Twitter, Flickr, Yahoo, Dropbox, every photo sharing site, every web forum, etc. it is extremely easy to upload attachments no matter what web browser you use.
    Of course, they'll get very defensive if you try to tell them that their systems are totally out of date and any browser should be able to upload attachments. Even if that's true, they may not be able to overhaul their systems any time soon. Maybe they would like to, but they can't get the funding. The problem for them is that more and more devices are being used on their network which don't have Internet Explorer, like Macs, phones, and tablets, and it's revealing the limitations of their system.
    That's the situation. It won't be easy to fix because it requires that the school's systems be modernized. But they really need to be modernized, because as we saw, attachments are no problem on multiple browsers on all the other web sites we use every day.
    If they could update their systems, the benefits would be significant. If their web site became standards compliant, it would automatically support smartphones, tablets, and Mac web browsers with probably very little extra work.

Maybe you are looking for

  • Error in using Control in PageFlow Portal deployment on Weblogic9.2

    I am developing a small portal application in Weblogic9.2 using workshop. It uses pageFlow portlets to access a Control that connects to a database. When i add the @Control annotation tag to my pagecontroller and deploy the application it gives the b

  • Help with a weird problem: MB Air, Internet, and Cinema Display

    I have the first MacBook Air, running the latest Leopard release. I use an Airport Extreme with Verizon FIOS. I have no problems connecting with the Internet (knock on wood) on the Air. However, when I use a 23-inch Cinema Display (not the most recen

  • How to create a hyperlink on a pop up window?

    Hi,         How to create a hyperlink on a pop up window? The pop up window appears on right click in a transaction. Thanks in advance, Regards, Varun

  • RFC in loop

    hi.. i used a rfc in a loop. every time in the pass the control is taking me to the logon of the remote system.but the control is not going into the respective function module..what is the problem

  • Online Indexing in SQL Server 2005 in SAP

    Hi SDN, I had a requirment where i need to create a index in SQLPLUS. please let me know the transaction code where we will create index in SAP with SQLPLUS. i need to create index with code like this. create index z03 on AFRU (fileds) online = ON. p