Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3607818
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:25:26+00:00 2026-05-18T21:25:26+00:00

I have a custom iterator (TokenIterator to be precise, which iterates, well, tokenized php

  • 0

I have a custom iterator (TokenIterator to be precise, which iterates, well, tokenized php code). Items are simple objects (“property bags” with some normalisation methods added)

I have to implement search functionality, which have to find if
1. one iterator contains another or
2. two (or more) iterators are overlapping (with some parametrisation).

Currently i use naive approach to (1) – O(NxM) double loop search, and (2) is not implemented yet.

Before starting to reimplement really smart string-search algorithms I would like to know if there exists some effective implementation of that? Maybe something buried deep in some framework or generic library to reuse? And which algorithm will be most suitable here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:25:27+00:00Added an answer on May 18, 2026 at 9:25 pm

    The first thing that comes to mind is that you’re talking about set operations, for which iterators are arguably not the best solution.

    I don’t know if there’s any existing solution for your problem, but, as a general solution, I’d use hash tables. For example, construct a hash table using the tokens of the first set (I’ll call it set from now on, since I feel Iterator is not the best word) and you can do it in Theta(N), and then try to insert the other set in the same hash table. The first time you get a collision, you’ll know there’s an overlap. Of course this works well if the hash space is wide and the hash function guarantees a negligible amount of collisions, however it is always possible to code some sort of workaround.

    Given PHP has associative arrays (which are a form of hash tables) you can also create an array having the tokens as the keys, which again can be done in Theta(N), and then use array_key_exists. It is absolutely possible that array_key_exists is nothing more than a linear scan of the list of keys, as I am not familiar with PHP’s internals, but I’m quite confident that if associative arrays are implemented as hash tables, it should be implemented much more efficiently than a linear scan.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom container class for which I'd like to write the iterator
I have a custom made class called Graph in which I use adjacency lists.
I have custom components which must adjust their text content based on space constraints.
I have custom view in my application which can be scrolled by the user.
I have the following custom iterator: class PetIterator<T extends Pet> implements Iterator<T> I have
I have nested iterator in my custom stack template class. The problem I get
I have custom coded several enterprise applications for mid to large organizations to use
I have custom errors configured in my web.config, but IIS 6.0 is returning the
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a few models that need to have custom find conditions placed on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.