- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
replace treemap with a balanced tree #4487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
        
      
    
                
     Closed
            
            
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    | This rewrite looks good to me. Can you run it through  | 
| @brson: tidy warnings are fixed now (I just fixed all the things that had FIXMEs). It's all working well so it should be good to merge. | 
| landed in c7abdd3 | 
  This was referenced Jan 20, 2013 
      
    
  RalfJung 
      pushed a commit
        to RalfJung/rust
      that referenced
      this pull request
    
      Jul 23, 2025 
    
    
      
  
    
      
    
  
Automatic Rustup
    
  RalfJung 
      pushed a commit
        to RalfJung/rust
      that referenced
      this pull request
    
      Jul 25, 2025 
    
    
      
  
    
      
    
  
Automatic Rustup
    
  RalfJung 
      pushed a commit
        to RalfJung/rust
      that referenced
      this pull request
    
      Jul 28, 2025 
    
    
      
  
    
      
    
  
Automatic Rustup
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This is a full replacement for TreeMap as a balanced tree (AA Tree). I started from scratch so there aren't many similarities with the old implementation.
Improvements over the old implementation:
CopyorClone(only uses moves) and there's no usage of@EqTreeSetwrapper, which will include O(n + m) implementations ofis_disjoint,is_subset,is_superset,difference,symmetric_difference,intersectionandunionIn the future someone might want to replace this with a full red-black tree, but I think the performance will be pretty competitive as-is (and the asymptotic complexity would be the same). The constant factor for insertion is likely higher than a full rbtree implementation, but searching will be a bit quicker since the tree will usually be a bit more balanced.
Closes #2010, #2808.