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 41329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:09:49+00:00 2026-05-10T15:09:49+00:00

I need to implement an in-memory tuple-of-strings matching feature in C. There will be

  • 0

I need to implement an in-memory tuple-of-strings matching feature in C. There will be large list of tuples associated with different actions and a high volume of events to be matched against the list.

List of tuples:

('one', 'four') ('one') ('three') ('four', 'five') ('six')     

event (‘one’, ‘two’, ‘three’, ‘four’) should match list item (‘one’, ‘four’) and (‘one’) and (‘three’) but not (‘four’, ‘five’) and not (‘six’)

my current approach uses a map of all tuple field values as keys for lists of each tuple using that value. there is a lot of redundant hashing and list insertion.

is there a right or classic way to do this?

  • 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. 2026-05-10T15:09:50+00:00Added an answer on May 10, 2026 at 3:09 pm

    If you only have a small number of possible tuple values it would make sense to write some sort of hashing function which could turn them into integer indexes for quick searching.

    If there are < 32 values you could do something with bitmasks:

    unsigned int hash(char *value){...}  typedef struct _tuple {     unsigned int bitvalues;     void * data } tuple;  tuple a,b,c,d; a.bitvalues  = hash('one'); a.bitvalues |= hash('four'); //a.data = something;  unsigned int event = 0; //foreach value in event; event |= hash(string_val);  // foreach tuple if(x->bitvalues & test == test) {      //matches } 

    If there are too many values to do a bitmask solution you could have an array of linked lists. Go through each item in the event. If the item matches key_one, walk through the tuples with that first key and check the event for the second key:

    typedef struct _tuple {     unsigned int key_one;     unsigned int key_two;     _tuple *next;     void * data; } tuple;  tuple a,b,c,d; a.key_one = hash('one'); a.key_two = hash('four');  tuple * list = malloc(/*big enough for all hash indexes*/ memset(/*clear list*/);  //foreach touple item if(list[item->key_one])    put item on the end of the list; else    list[item->key_one] = item;   //foreach event    //foreach key       if(item_ptr = list[key])         while(item_ptr.next)            if(!item_ptr.key_two || /*item has key_two*/)               //match            item_ptr = item_ptr.next; 

    This code is in no way tested and probably has many small errors but you should get the idea. (one error that was corrected was the test condition for tuple match)


    If event processing speed is of utmost importance it would make sense to iterate through all of your constructed tuples, count the number of occurrences and go through possibly re-ordering the key one/key two of each tuple so the most unique value is listed first.

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your question actually boils down to object caching and reuse.… May 12, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer It is propriety Microsoft gubbins. It doesn't work in lots… May 12, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer About URI: in general all URI cannot be referenced: for… May 12, 2026 at 1:06 am

Related Questions

I have a large database and want to implement a feature which would allow
After writing out some processed content to an output stream, I need to revisit
I'm very new to TDD and I'm having trouble with one of my unit
I want to compare the current value of an in-memory Hibernate entity with the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.