What is represent by edges when facebook using graph data structure - facebook-graph-api

when learning graph data structure I learned that facebook also use it.And I know nodes represent persons. is edge represent connections between them? when we become a friend with them is there a edge between me and that new friend?

yes. new connection established and to show connections those social networks use breadth first search(BFS)

Related

Spring Data Neo4j 6 Relationship.UNDIRECTED

I'm upgrading my code to use Spring Data Neo4j 6.1.2
With an earlier version, I was able to set the relationship direction as UNIDIRECTED:
#Relationship(type = RelatedEntity.TYPE, direction = Relationship.UNDIRECTED)
private Set<RelatedEntity> relatedEntities = new HashSet<>();
With this, I could get mutual relationships from either node. I assume this was internally ignoring the direction in the generated cypher code.
In the latest version, I only see INCOMING and OUTGOING. Is there a way I can replicate the previous behaviour or would I have to write custom queries?
There is no replacement for the UNDIRECTED relationship.
Spring Data Neo4j 6 requires you to specify the very same direction that you have in your data. If you need a bidirectional definition, e.g.
(user1)-[knows]->(user2)-[knows]->(user1)
you would have to add the relationship as INCOMING and OUTGOING to the entity.

Data structure for managing contact-collision info between particles

I am performing some particle simulations in C++ and I need to keep a list of contacts info between particles. A contact is actually a data struct containing some data related to the contact. Each particle is identified with a unique ID. Once a contact is lost, it is deleted from the list. The bottleneck of the simulation is computing the force (a routine inside the contacts), and I have found an important impact on the overall performance according to the actual way the contact list is organised.
Currently, I am using a c++ unordered_map (hash map), whose key is a single integer obtained from a pair function applied over the two unique IDS of the particles, and the value is the contact itself.
I would like to know if there is a better approach to this problem (organising efficiently the list of contacts while keeping the info of the particles they are related with) since my approach is done just because I read and found than a hash map is fast for both insertion and deletion.
Thanks in advance.

Complex and interrelated data structure in the Client Server scenerio

I need to know efficient mechanism used for data structure in the socket programming. Lets consider an example of car manufacturing on assembly line.
Initially Conveyer is empty then i start adding different parts dynamically. How can i transmit my data to the server using the TCP/UDP. What can i do so that my server can recognize, if i add some new part dynamically ? and after calculating server return data to client in same structure, so that client can put calculated data on the exact position of component.
Is it possible to arrange this data using some B Tree or B+ Tree structures ? is it possible to reconstruct the same tree on the server side ? what could be other possible alternatives approaches to do this ?
You need to serialize your data, whatever you need to send to server, to some text or binary blob. Yeah, it's possible to serialize interrelated data structure, e.g. by assigning some ID to items and then referencing them by that ID. For C++ serialization I would recommend to have a look at Boost.Serialization.
The simplest ID is memory address on serializer (sender) side - kind of unique identifier ready to use. Of course on deserializer side it must be considered as a just ID and not a memory address.

Get elements from database based on distance from a point

Im pretty new to backend web design, but I am building a webapp and will have a database of locations. As the database gets big, I realized that if I want people to be able to access the database and say, for example, see points around them, it would take a long time to go through every element and check the distance from them to any given point.
Does anyone know of a way to quickly check the database, but maybe only relevant locations?
Im using python, django, and SQL if that makes any difference.
The way to quickly access data in a database is adding keys. But “regular“ keys operate on a strict ordering of possible values, i.e. a 1D domain. Geographical locations would require 2D access. There are basically two approaches you can use:
Use specific 2D functionality provided by your DBMS, e.g. Spatial Extensions for MySQL.
Use space-filling curves like the Z-order curve for your index, so that close points will correspond to a small number of small intervals in the index space.
You might also want to look at related tags, e.g. geographical-information and nearest-neighbor, or at related questions like the one about K-Nearest neighbours. And you might want to give more details on the database system you're working with.

Client Server Many To Many Design Model (Many Users - Many Applications) in C++

I need to create a mapping records of users and applications (many to many model) in c++. One users can have many applications connected to it, and vice versa, one application can have many users connected to it.
I have 2 design model, as follow:
First Design
unordered_map <string, unordered_set<string> > OneToManyMapping;
OneToManyMapping userAppMappings; // mapping records of 1 user to all application that it connects to.
OneToManyMapping appUserMappings; // mapping records of 1 application to all users that connects to it.
So every time a user is connected to new applications, we do not have to create a new record, but just insert the new application id to the unordered_set element of the userAppMappings. And same case for the appUserMappings. (every time a new user connects to it, we just insert the new user Id to the unordered_set element of the appUserMappings.
Second Design
unordered_multimap <string, string > ManyToManyMapping;
ManyToManyMappings userAppMappings; // mapping records of many user to many applications.
ManyToManyMappings appUserMappings; // mapping records of many applications to all users.
Every time a user is connected to a new application, we have to create new record on the userAppMappings. Same case with the appUserMappings.
Which design would be the most efficient if I want it to support the following operations:
Insertion,
Deletion,
Access (get list of all applications, or list of all users, or get list of all applications which is connected to a user, or get list of all users connected to an application ),
Delete all applications connected to a user, delete all users connected to an application, etc?
What will be the pro and cons if I use the first design or the second design? Is mapping the ID of the user and application a good approach, or is it better to map the complete User object and Application object?
Is there any other better design? Please advise.
Your second design will not work as many to many mapping, unordered_map key should be unique, that is you will not be able to store different records for the same user/application. What you are asking is multimap container, see http://en.wikipedia.org/wiki/Multimap.