Code Monkey home page Code Monkey logo

sorteddictionary's Introduction

Getting started with SortedDictionary

Introduction

Writing for OS/X or the iPhone? Using NSDictionary to store and access key-value pairs? Ever tried to enumerate them all only to find they come back in some random order? As NSDictionary uses a hash table to map keys to values, it maintains no sort order whatsoever across its entries. The SortedDictionary class and its mutable companion, MutableSortedDictionary implement dictionaries that maintain a strong sort order across their keys. SortedDictionary and MutableSortedDictionary deliver high performance using an implementation of a self-balancing binary tree.

Capabilities

The SortedDictionary and MutableSortedDictionary classes implement the interfaces of NSDictionary and NSMutableDictionary, respectively, and can serve as drop-in replacements. They support the NSCoding, NSCopying and NSMutableCopying protocols. Additionally, the sorted dictionary classes add methods allowing you to enumerate entries in both their forward and reverse key order, without having to sort and without any additional computational cost.

How to use SortedDictionary in your code

Option 1: Using the source code

Add the SortedDictionary folder to your project. Add all the files in the SortedDictionary folder, including its Internal and External folders, into your project. When you build your project, the sorted dictionaries classes will be compiled into your application. To create a sorted dictionary in code, include the appropriate header file:

#import "SortedDictionary.h"

- (void) someMethod {
   SortedDictionary *dict = [MutableSortedDictionary dictionary];

   [dict setValue: @"red" forKey: @"apple"];
   [dict setValue: @"yellow" forKey: @"banana"];
   [dict setValue: @"orange" forKey: @"orange"];

   NSString *color = [dict objectForKey: @"apple"];
}

Option 2: Using the compiled frameworks

Add the compiled frameworks to your project:

In XCode, open Targets, then right-click (or ctrl-click) your target, and select Add>Existing Frameworks...

The Target Info window opens. Click the + button below the Linked Libraries list. Select Add Other...

Navigate to the folder that contains the compiled framework, and select SortedDictionary.Framework.

Click Add, and close the Target Info window.

License

MIT License

Copyright (c) 2009 Oren Trutner

Modified by Yuriy Shevchuk, struktur AG, on 8/30/2013.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sorteddictionary's People

Contributors

ivansss avatar

Watchers

James Cloos avatar Abbas Raza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.