DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Implementing Low-Level Trie: Solving With C++

Implementing Low-Level Trie: Solving With C++

Check out Ayende's nice walk through of creating a low level trie in C++, but first he offers up a warning of trying to do the same in Rust. Full source code is provided via GitHub.

Oren Eini user avatar by
Oren Eini
·
Jan. 27, 17 · Web Dev Zone · Tutorial
Like (2)
Save
Tweet
3.52K Views

Join the DZone community and get the full member experience.

Join For Free

The low-level trie question has been a favorite question of mine for a while. It is simple in concept, but the limitations placed on it make it pretty hard to actually build. Previous posts in this series outlined the approach I had for solving this, but I always got caught up with something and didn’t get around to actually sitting down and resolving this completely.

As part of learning Rust, I decided to go ahead and implement this low-level trie using Rust. I failed, it was just too much babysitting by the compiler and having to fight it. I knew exactly what I wanted to do, but I kept having to jump through hoops to get it to it. Eventually, I just called it quits and decided to abandon the attempt to use Rust.

But I still want to do something out of my comfort zone, so I decided to run this exercise using C++. Now, I used to write quite a lot of C++ (along with VB, VBScript, and ASP classic). But that was in the late 90's, and very early 2000's. I heard it through the grapevine that someone kicked the C++ standard committee into high gear and started to actually improve the language.

The result was three evenings spent on building a low-level trie impl in C++, and it was quite a lot of fun. I’ll have another post about the actual details of the implementation, but in this post, I mostly wanted to talk about the experience of getting back to C++. And it is… strange.

On the one hand, because I’m so used to C# and have used C++ before, this is oh so comfortable. Like wearing an old set of gloves that you forgot that you even had.

On the other hand, I'd forgotten quite a lot of details about the language and the libraries, and they changed. My old C++ code would be newing up stuff and fighting to manage memory and very likely leaking like crazy. In this codebase? I don’t have a single new call throughout. And being able to do things like lambdas in C++ feels like magic.

I’ll admit that the codebase is heavily influenced by my Rust work. To start with, I’m using snake_case convention, and I found that I’m using a lot more std::pair that I would expect myself to use.

I would appreciate any code review on this, the core code is about 400 lines or so, and I’m mostly interested to know whatever I managed to write idiomatic modern C++, and if not, how this can be improved.

GitHub:  https://github.com/ayende/trie-cpp

c++ Rust (programming language) POST (HTTP) Concept (generic programming) Memory (storage engine) GitHub GloVe (Machine learning)

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • SQL vs. NoSQL: Pros and Cons
  • 5 Myths of Kubernetes
  • How to Submit a Post to DZone
  • What I Miss in Java, the Perspective of a Kotlin Developer

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo