Add user permission to content node
Your question looks like a perfect fit for the Group module, which can be used to create collections of content (nodes) that can be accessed by sets of users and with variations of access levels, such as none or read only.

Have a look at the answer to What are the alternatives for the Organic groups module? for a brief introduction to the Group module.

For this specific question, here is a blueprint of how it could be used/configured:


Group Type: Collections
Group Roles (refer to "What are the various roles supported by the Group module?" for more details):


Group Owner
Group Fans (or whatever fits), used for those who have access to a selected collection.

Groups (adapt the group titles to fit your collection names):


Collection 1 of user A.
Collection 2 of user A.
Collection 1 of user B.
Collection 2 of user B.
Collection 3 of user B.
...
Collection I of user X.

If a user creates a new group, then automatically assign role "Group Owner"-role to the user who created the group.
Group permissions: grant permission to the user with role "Group Owner" to perform actions like "Add members" or "Invite members to join".


To use the Group module from within a custom module, start from its Development guide and/or have a look at its API for D7 or API for D8.

Resources


Community documentation for the Group module.
Video tutorial "How to use the Group module in Drupal 8 to manage editorial access control to different areas of a web site".
Other questions tagged with the group tag.


PS: Even though this question is tagged for D8, this answer applies for either D7 or D8 ...