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

  • Home
  • SEARCH
  • 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
  • 1 View
  • 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

Related Questions

I need to implement a very large matrix, say NxN in Standard C. The
I need to implement simple thread-safe memory management preventing fragmentation. I've read some articles
I need to implement a Routing Table where there are a number of paramters.
I need to implement a large collection of Widget objects, each of which contain
I need ideas to implement a (really) high performance in-memory Database/Storage Mechanism in Java.
I need ideas to implement a (really) high performance in-memory Database/Storage Mechanism. In the
I have a large database and want to implement a feature which would allow
I need to implement a custom handler for MVC that gives me the first
I need to implement login velocity checking for a web service. The service is
I need to implement Integrated Windows Authentication for a WCF service hosted on IIS

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.