Willem Olding
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# The unordered set collection in the Holochain DHT The unordered set is one of the fundamental data structures provided by most modern languages. It is characterised by the following operations - `insert(item)` Inserts a new item into the set. Will de-dup if required. - `remove(item)` Remove an item from the set - `contains(item)` Returns a boolean if the given item is contained in the set - `items()` Return all items in the set. This of course has no ordering requirements and will contain no duplicates. Other set operations such as unions etc will not be considered at this time. ## First approach Sets are commonly implemented using search trees or hash tables and a similar approach is proposed for storing in the Holochain DHT. The hash space should be partitioned into smaller buckets which are not expected to contain more entries than can be processed by a single agent. This is similar to how entries in the DHT are distributed to different agents but with no redundancy factor. This introduces a trade-off between having many buckets with few entries and few buckets with many entries. Both have drawbacks depending on the usage requirements. Let $B$ be the number of bits in the prefix of the hash allocated to the bucket identifier. There will be $N_{buckets} = 2^B$ buckets. For the 256 bit Hashes used by Holochain the maximum number of entries per bucket is therefore $E_{max} = 2^{(256 - B)}$. This upper bound is still extremely large for any reasonable number of buckets (in the order of $10^{70}$). What should actually be taken into consideration is the expected number of items per bucket which is, thanks to the uniform distribution, the expected number of items divided by the number of buckets. Let us take the example of Twitter's $260 * 10^6$ registered users. These users could be kept track of using a Set. By varying the prefix size you can see the expected number of users linked per bucket. $B$ | $N_{buckets}$ | $E_{avg}$ ----- | ----- | ----- 0 | 1 | 260000000 4 | 16 | 65000000 8 | 256 | 1015625 10 | 1024 | 253906 12 | 4096 | 63477 With a reasonable number of buckets it is foreseeable how a twitter scale application could exist on Holochain. 4k buckets is not an unreasonable number to scan (and this would be an unusual operation. How often do you retrieve all twitter users?) and 63k entries is likely small enough to fit in WASM memory. Furthermore very few applications are at the scale of twitter so these numbers should be vastly smaller in most cases. ### Operations - `insert` - Hash the entry - calculate the correct bucket based on the prefix - link the entry to the bucket - `remove` - hash the entry - calculate the correct bucket - mark the link between bucket and entry as deleted - `contains` - hash the entry - calculate the correct bucket - retrieve all links - scan links for existence of hash (Note this can be performed in O(1) if it is known the entry does not exist unless it is in the set. Then ) - `items` - Iterate over buckets - retrieve links from each bucket ## Adaptive Approach The success and longeivity of bitcoin can be in part attributed to its dynamic difficulty adjustment. One could argue that truly scaleable distributed applications required some degree of dynamism in order to successfully bootstrap and then scale. The approach suggested above required some estimation on the part of the DNA developer of the number of users such that a sensible trade-off bucket size could be selected. This will likely be too many buckets at the start of the hApps life and perhaps not enough if there is strong adoption. An ideal set would increase the number of buckets only when it is required to do so to keep link numbers below some threshold to prevent DHT hotspots and retrieval issues. The dynamic set should start with $B=0$ and when an agents detects there is more than some threshold number of links when trying to insert, they instead create the next layer bucket and insert there. Of course this is susceptible to the classic partition attacks so something needs to be figured out there. The resulting data structure is a binary tree of buckets that span the hash space with increasing granularity. Early entries will be added further up the tree and later ones further down. As a result the `insert`, `delete` and `contains` operations become $O(log(n))$ as they require traversal down a single path in the tree. The `items` opertaions also becomes more expensive as it has to scan the links from all nodes in the tree. ### Operations - `insert` - Hash the entry - go to the first bucket - check the bucket, if non-full insert there - else figure out the next bucket based on the hash - repeat above 3 steps until non-full bucket found - `remove` - Hash the entry - go to the first bucket - check the bucket to see if entry is there. If so remove it - else figure out the next bucket based on the hash - If end of tree reached then abort - `contains` - Hash the entry - go to the first bucket - check the bucket to see if entry is there - else figure out the next bucket based on the hash - If end of tree reached then return false - `items` - traverse tree - retrieve links from each bucket and collect ### Summary It is important that such a set collection dynamically scales with the number of items added. This presents a possible approach however it suffers from the classic attack where a partitioned node is out of sync with the data structure, can add entries to the root, and upon rejoining will effectively flood it with entries. By repeating this it is possible to add an infinite number of entries to the root, thus making the data structure useless. The solution to this problem requires some type of consensus which is beyond the scope of this document.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully