SPB Git

spb/forge Public MIT

Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.

C++ 61.2% C 23% Python 7.6% TeX 7.2% CMake 1.1%
5.6 KB · 129 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Foundation/NSDictionary.hpp4//5// Copyright 2020-2024 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223//-------------------------------------------------------------------------------------------------------------------------------------------------------------2425#include "NSEnumerator.hpp"26#include "NSObject.hpp"27#include "NSTypes.hpp"2829//-------------------------------------------------------------------------------------------------------------------------------------------------------------3031namespace NS32{33class Dictionary : public NS::Copying<Dictionary>34{35public:36    static Dictionary* dictionary();37    static Dictionary* dictionary(const Object* pObject, const Object* pKey);38    static Dictionary* dictionary(const Object* const* pObjects, const Object* const* pKeys, UInteger count);3940    static Dictionary* alloc();4142    Dictionary*        init();43    Dictionary*        init(const Object* const* pObjects, const Object* const* pKeys, UInteger count);44    Dictionary*        init(const class Coder* pCoder);4546    template <class _KeyType = Object>47    Enumerator<_KeyType>* keyEnumerator() const;4849    template <class _Object = Object>50    _Object* object(const Object* pKey) const;51    UInteger count() const;52};53}5455//-------------------------------------------------------------------------------------------------------------------------------------------------------------5657_NS_INLINE NS::Dictionary* NS::Dictionary::dictionary()58{59    return Object::sendMessage<Dictionary*>(_NS_PRIVATE_CLS(NSDictionary), _NS_PRIVATE_SEL(dictionary));60}6162//-------------------------------------------------------------------------------------------------------------------------------------------------------------6364_NS_INLINE NS::Dictionary* NS::Dictionary::dictionary(const Object* pObject, const Object* pKey)65{66    return Object::sendMessage<Dictionary*>(_NS_PRIVATE_CLS(NSDictionary), _NS_PRIVATE_SEL(dictionaryWithObject_forKey_), pObject, pKey);67}6869//-------------------------------------------------------------------------------------------------------------------------------------------------------------7071_NS_INLINE NS::Dictionary* NS::Dictionary::dictionary(const Object* const* pObjects, const Object* const* pKeys, UInteger count)72{73    return Object::sendMessage<Dictionary*>(_NS_PRIVATE_CLS(NSDictionary), _NS_PRIVATE_SEL(dictionaryWithObjects_forKeys_count_),74        pObjects, pKeys, count);75}7677//-------------------------------------------------------------------------------------------------------------------------------------------------------------7879_NS_INLINE NS::Dictionary* NS::Dictionary::alloc()80{81    return NS::Object::alloc<Dictionary>(_NS_PRIVATE_CLS(NSDictionary));82}8384//-------------------------------------------------------------------------------------------------------------------------------------------------------------8586_NS_INLINE NS::Dictionary* NS::Dictionary::init()87{88    return NS::Object::init<Dictionary>();89}9091//-------------------------------------------------------------------------------------------------------------------------------------------------------------9293_NS_INLINE NS::Dictionary* NS::Dictionary::init(const Object* const* pObjects, const Object* const* pKeys, UInteger count)94{95    return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(initWithObjects_forKeys_count_), pObjects, pKeys, count);96}9798//-------------------------------------------------------------------------------------------------------------------------------------------------------------99100_NS_INLINE NS::Dictionary* NS::Dictionary::init(const class Coder* pCoder)101{102    return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(initWithCoder_), pCoder);103}104105//-------------------------------------------------------------------------------------------------------------------------------------------------------------106107template <class _KeyType>108_NS_INLINE NS::Enumerator<_KeyType>* NS::Dictionary::keyEnumerator() const109{110    return Object::sendMessage<Enumerator<_KeyType>*>(this, _NS_PRIVATE_SEL(keyEnumerator));111}112113//-------------------------------------------------------------------------------------------------------------------------------------------------------------114115template <class _Object>116_NS_INLINE _Object* NS::Dictionary::object(const Object* pKey) const117{118    return Object::sendMessage<_Object*>(this, _NS_PRIVATE_SEL(objectForKey_), pKey);119}120121//-------------------------------------------------------------------------------------------------------------------------------------------------------------122123_NS_INLINE NS::UInteger NS::Dictionary::count() const124{125    return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(count));126}127128//-------------------------------------------------------------------------------------------------------------------------------------------------------------129