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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:21:37+00:00 2026-05-15T13:21:37+00:00

I need to store a graph for the map of a game inside a

  • 0

I need to store a graph for the map of a game inside a game server written in C.

The graph has ~200 nodes and 3 kinds of edges that can connect two nodes (these three kind can also overlap: a node can be connected by 2 edges of two different types for example). The maximum degree of a node is something like 5-6 nodes.

What I would like to have is to have this static structure implemented in an efficient way to allow me to do simple operations like

  • is n1 connected to n2? (with all kinds of edges in case of affermative response)
  • what is n1 connected to? (with all kinds of edges or a specific one)

but in a multi-threaded environment since there will be many instances of the game that relies on the same static graph.

Since the graph can’t be modified and the structure is well known I’m sure there are some tricks to implement it in a cool fashion to use least resources possible.

I would like to avoid using STL or Boost for now.. do you have any clues on a data structure that could suit well?

(it’s not a premature optimization, the fact is that it will run on a vps and I don’t have many ram neither cpu power so I need to keep it tight)

EDIT: just because I forgot (and thanks to make me realize it) the graph is undirected so every edge is symmetric..

Thanks in advance

  • 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-15T13:21:37+00:00Added an answer on May 15, 2026 at 1:21 pm

    Many answers are possible. This one relies on the fact that you have relatively few nodes. The advantage of this approach is probably unbeatable performance.

    The idea is to represent your graph as a 200×200 matrix of bytes, each entry representing an edge. The byte gives you 256 different possible values, where a 0 will obviously mean “no connection” and any non-zero combination of bits can represent up to 8 different edge types.

    Let the “row” of this matrix be the starting node and the “column” be the destination. Initialize the structure such that for every edge connecting one node with another, there’s a value at the intersection of starting / ending. That value can be a combination of bits representing edge types.

    To find out whether one node connects to another, simply query the byte at the intersection of one node and the other: If there’s a nonzero value there, then there is a connection, and the value will tell you what kind.

    For 200 nodes, this data structure will eat up 40 KB, which is pretty moderate. It won’t scale too well once you get beyond, say, 1000 nodes.

    As long as nothing (apart from one-time initialization) ever writes to this structure, it will be naturally thread safe, as its state never changes.

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

Sidebar

Related Questions

I need to store a non directed graph with multiple nodes (unknown to the
Graph databases store data as nodes, properties and relations. If I need to retrieve
I have id values for products that I need store. Right now they are
I need to store app specific configuration in rails. But it has to be:
I need to store a undirected graph in a Google App Engine database. For
I need to store some data that looks a little like this: xyz 123
I need to store a large and dynamic undirected graph in google appengine, what's
Let's say I have a graph with heavy nodes, that is each node is
In a graph class I need to handle nodes with integer values (1-1000 mostly).
Background: I need to store the following data in a database: osm nodes with

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.