首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏Lua学习笔记

    Lua源码学习笔记-从TValue开始的数据类型

    前言以下源码基于lua-5.4.8基本数据类型在了解TValue之前,我们要先知道lua的一些基本数据类型// lobject.h/*** basic types*/#define LUA_TNONE( 请看以下TValue相关源码TValueValue 是Lua内部用来表示所有可能的值的一个联合体。Lua是一种动态类型语言,它的变量可以随时改变类型,比如从数字变为字符串、表等。 为了在内部高效地表示这些值,Lua使用了一个联合体 Value 来存储所有可能的数据类型,同时TValue配合一个“类型标签”(tt_)来标识当前存储的具体是什么类型.在Lua中的任何数据都可以通过该结构体进行表示 { TValuefields;} TValue;/*** 所有可垃圾回收对象的公共头部(用宏定义,会被包含进具体对象中)** next 指针 指向下一个GC对象** tt GC对象的实际类型(比如上面 当Lua创造一个可GC对象时(以TString为例),TValueTValue.tt_ 被设为 ctb(LUA_TSTRING),其 value_.gc 字段指向一个TString,而该对象也将以 CommonHeader

    25700编辑于 2025-08-08
  • 来自专栏C#

    C#创建安全的字典(Dictionary)存储结构

    public void Add(TKey key, TValue value) { Insert(key, value, true); } private >>, IDictionaryEnumerator { private Dictionary<TKey,TValue> dictionary "></typeparam> public class TDictionary<TKey, TValue> : IDictionary<TKey, TValue> { / > dictionary) { _mDictionary = new Dictionary<TKey, TValue>(dictionary); >(dictionary, comparer); } public TValue GetValueAddIfNotExist(TKey key, Func<TValue

    2.9K60发布于 2018-01-04
  • 来自专栏Linux云计算网络

    算法导论第十三章 红黑树

    附上左旋的代码(C++模板类): 1 //左旋 2 template<typename TKey, typename TValue> 3 void RBTree<TKey, TValue>::_ > 11 typename RBTree<TKey, TValue>::RBTreeNode * RBTree<TKey, TValue>::m_pNil = NULL; 12 13 template <typename TKey, typename TValue> 14 RBTree<TKey, TValue>::RBTree() 15 { 16 if ( ! > 107 typename RBTree<TKey, TValue>::RBTreeNode* RBTree<TKey, TValue>::Search( TValue const &value ) > 117 bool RBTree<TKey, TValue>::Insert( TKey key, TValue value ) 118 { 119 if ( Search(value)->

    99680发布于 2018-01-11
  • 来自专栏全球技术精选

    使用 C# 9 的records作为强类型ID - 路由和查询参数

    , object> GetFactory<TValue>(Type stronglyTypedIdType) where TValue : notnull { return CreateFactory<TValue>); } private static Func<TValue, object> CreateFactory<TValue>(Type stronglyTypedIdType ) where TValue : notnull { if (! public class StronglyTypedIdConverter<TValue> : TypeConverter where TValue : notnull { private [TypeConverter(typeof(StronglyTypedIdConverter))] public abstract record StronglyTypedId<TValue>(TValue

    2.7K20发布于 2021-01-21
  • 来自专栏walterlv - 吕毅的博客

    .NET/C# 使用 ConditionalWeakTable 附加字段(CLR 版本的附加属性,也可用用来当作弱引用字典 WeakDictionary)

    本文介绍 .NET 的 ConditionalWeakTable<TKey,TValue> 类型,适用于 .NET Framework 4.0 以上和全部 .NET Core 的版本。 ---- 这不是字典 现成可用的弱引用字典,即 ConditionalWeakTable<TKey,TValue>。然而实际上这个类的原本作用并不是当作字典使用! 实际上 .NET 中提供了 ConditionalWeakTable<TKey,TValue> 帮我们解决了最本质的问题——在部分场景下期望为 Foo 类添加一个字段。 你需要注意的是,ConditionalWeakTable<TKey,TValue> 并不实现 IDictionary<TKey,TValue> 接口,只是里面有一些像 IDictionary<TKey, TValue> 的方法,可以当作字典使用,也可以遍历取出剩下的所有值。

    67410编辑于 2023-10-22
  • 来自专栏CSharp编程大全

    C# Dictionary 字典

    Keys 获取包含 Dictionary<TKey, TValue> 中的键的集合。 Values 获取包含 Dictionary<TKey, TValue> 中的值的集合。 Clear 从 Dictionary<TKey, TValue> 中移除所有的键和值。 ContainsKey 确定 Dictionary<TKey, TValue> 是否包含指定的键。 ContainsValue 确定 Dictionary<TKey, TValue> 是否包含特定值。

    1.5K20发布于 2021-03-16
  • 来自专栏撸码那些事

    C#集合类型大揭秘

    2.SortedDictionary<TKey,TValue> **SortedDictionary<TKey,TValue>和Dictionary<TKey,TValue>**类似,至于区别我们从名称上就可以看出来 ,**Dictionary<TKey,TValue>**是无序的,**SortedDictionary<TKey,TValue>**则是有序的。 相对于下面提到的SortedList<TKey,TValue>**来说,SortedDictionary<TKey,TValue>在添加和删除元素时更快一些。 ,TValue>就无能为力了,因为Dictionary<TKey,TValue>使用了散列函数,并不支持线性排序。 **SortedList<TKey,TValue>和SortedDictionary<TKey,TValue>同时支持快速查询和排序,SortedList<TKey,TValue> 优势在于使用的内存比

    1.6K70发布于 2018-06-15
  • 来自专栏程序随笔

    C# SortedDictionary以及SortedList的浅谈

    ) as opposed to O(n) for SortedList<TKey, TValue>. <TKey, TValue>. 这两个类的不同之处在于内存的使用以及插入和删除的速度: SortedList<TKey, TValue>比SortedDictionary<TKey, TValue >使用更少的内存. SortedDictionary<TKey, TValue>对于未排序的数据O(log n)具有更快的插入和删除操作,而SortedList<TKey, TValue>的插入和删除都是O(n) 如果列表是由已排序的数据一次填充的 ,那么SortedList<TKey, TValue>要比SortedDictionary<TKey, TValue>快。

    57400编辑于 2023-10-19
  • 来自专栏大内老A

    自定义Key类型的字典无法序列化的N种解决方案

    override Dictionary<Point, TValue>? Dictionary<Point, TValue> 对象转换成Dictionary<string, TValue> 交给它进行序列化。 override Dictionary<Point, TValue>? = (JsonConverter<TValue>)options.GetConverter(typeof(TValue))!; dictionary ?? = (JsonConverter<TValue>)options.GetConverter(typeof(TValue))!

    57810编辑于 2024-03-20
  • 来自专栏哲学驱动设计

    SortedList<TKey,TValue> 和 SortedDictionary<TKey,TValue>

    The SortedList<TKey, TValue> generic class is a binary search tree with O(log n) retrieval, where n In this, it is similar to the SortedDictionary<TKey, TValue> generic class. > uses less memory than SortedDictionary<TKey, TValue>. 2.SortedDictionary<TKey, TValue> has faster >. 3.If the list is populated all at once from sorted data, SortedList<TKey, TValue> is faster than SortedDictionary<TKey, TValue>.

    63870发布于 2018-01-26
  • 来自专栏魂祭心

    原 单例字典

    public abstract class BaseCache<Tkey,Tvalue> :CachesInterface<Tkey, Tvalue> { private Dictionary<Tkey, Tvalue> _innerStore; protected Dictionary<Tkey, Tvalue> DataStore { get { if (_innerStore == null) return _innerStore = new Dictionary<Tkey, Tvalue>( { CacheEnable = true;//暂时默认位true _innerStore = new Dictionary<Tkey,Tvalue >(); } public Tvalue GetCache(Tkey key) { Tvalue value = default(Tvalue)

    62240发布于 2018-05-17
  • 来自专栏张善友的专栏

    XML Serializable Generic Dictionary

    Dictionary<TKey, TValue>本身实现了ISerializable接口,WebService中无法实现序列化,具体是什么原因它不支持XML序列化。  Dictionary     ///      /// <typeparam name="TKey"></typeparam>     /// <typeparam name="<em>TValue</em> "></typeparam>     [XmlRoot("dictionary")]     public class SerializableDictionary<TKey, TValue>           : Dictionary<TKey, TValue>, IXmlSerializable     {  #region 构造函数         public SerializableDictionary ():base()         {         }                 public SerializableDictionary(IDictionary<TKey, TValue

    950100发布于 2018-01-29
  • 来自专栏跟着阿笨一起玩NET

    自定义Dictionary支持线程安全

    public class SafeDictionary<TKey, TValue> : IDictionary<TKey, TValue> { private readonly object syncRoot = new object(); private readonly Dictionary<TKey, TValue> d = new Dictionary< TKey, TValue>(); #region IDictionary<TKey,TValue> Members ///

    /// </param> /// <returns></returns> public bool TryGetValue(TKey key, out TValue value) > Dictionary<TKey,TValue>

    1.2K10发布于 2018-09-19
  • 来自专栏全球技术精选

    使用 C# 9 的records作为强类型ID - JSON序列化

    id序列化为其值而不是对象,我们需要编写一个通用的 JsonConverter: public class StronglyTypedIdJsonConverter<TStronglyTypedId, TValue > : JsonConverter<TStronglyTypedId> where TStronglyTypedId : StronglyTypedId<TValue> where TValue >(ref reader, options); var factory = StronglyTypedIdHelper.GetFactory<TValue>(typeToConvert) > : JsonConverter<TStronglyTypedId> where TStronglyTypedId : StronglyTypedId<TValue> where TValue >(reader); var factory = StronglyTypedIdHelper.GetFactory<TValue>(objectType); return

    2.2K10发布于 2021-01-21
  • 来自专栏.NET5

    携程 Apollo 配置中心传统 .NET 项目集成实践

    /// /// <typeparam name="<em>TValue</em>">值类型</typeparam> /// <param name="key">键</ GetDefaultValue<TValue>(string key, TValue defaultValue, params string[] namespaces); } } ConfigurationChangeEventArgs default(TValue) : (TValue)Convert.ChangeType(value, typeof(TValue), CultureInfo.InvariantCulture GetDefaultValue<TValue>(string key, TValue defaultValue, params string[] namespaces) { default(TValue) : (TValue)Convert.ChangeType(value, typeof(TValue), CultureInfo.InvariantCulture

    96340发布于 2019-08-07
  • 来自专栏全栈程序员必看

    C# SortedList类概念和示例

    TValue 集合中值的类型。 SortedList<TKey, TValue> 类型公开以下成员。 如果使用排序数据一次性填充列表,则 SortedList<TKey, TValue> 比 SortedDictionary<TKey, TValue> 快。 SortedDictionary<TKey, TValue> 类和 SortedList<TKey, TValue> 类之间的另一个区别是:SortedList<TKey, TValue> 支持通过由 SortedList<TKey, TValue> 中的每个键必须是唯一的。 键不能为 null,但如果列表中值的类型 TValue 为引用类型,则值可以。 SortedList<TKey, TValue> 的容量是指 SortedList<TKey, TValue> 可以保存的元素数。

    2.2K20编辑于 2022-07-15
  • 来自专栏草根专栏

    使用 Moq 测试.NET Core 应用 -- Mock 方法

    /Packages/Moq/Moq/It 它有下面几种用法: Is<TValue>(Expression<Func<TValue, Boolean>>) IsAny<TValue>() IsIn<TValue >(IEnumerable<TValue>) IsInRange<TValue>(TValue, TValue, Range) IsNotIn<TValue>(IEnumerable<TValue>) IsNotNull<TValue>() IsRegex(string) 我认为通过方法名就可以知道这些方法的用途.

    2.8K40发布于 2018-08-01
  • 来自专栏历史专栏

    【愚公系列】2023年03月 MES生产制造执行系统-004.Kafka的使用

    ">Message.Value 的数据类型</typeparam> public class KafkaConsumer<TKey, TValue> : KafkaConfig, IKafkaConsumer <TKey, TValue> { ///

    /// Kafka地址(包含端口号) /// public string Servers >(ConsumerConfig); //设置反序列化方式 builder.SetValueDeserializer(new KafkaDConverter<TValue >(ConsumerConfig); //设置反序列化方式 builder.SetValueDeserializer(new KafkaDConverter<TValue <TKey, TValue> { /// /// 构造生产者 /// public KafkaProducer() {

    69120编辑于 2023-03-16
  • 来自专栏高性能服务器开发

    算法导论第十三章 红黑树(2)

    TKey, typename TValue> 11RBTree<TKey, TValue>::RBTree() 12{ 13 if (! <typename TKey, typename TValue> 28void RBTree<TKey, TValue>::_RecursiveReleaseNode(RBTreeNode *node > 97typename RBTree<TKey, TValue>::RBTreeNode* RBTree<TKey, TValue>::Search(TValue const &value) 98 > 107bool RBTree<TKey, TValue>::Insert(TKey key, TValue value) 108{ 109 if (Search(value)->isValid > 356typename RBTree<TKey, TValue>::RBTreeNode * RBTree<TKey, TValue>::_Predecessor(RBTreeNode *node)

    44720发布于 2018-07-25
  • 来自专栏DotNet NB && CloudNative

    告别重复检查!C#通用结果模式重构全解析

    创建结果类型 public readonly struct Result<TValue, TError> { private readonly TValue? public static implicit operator Result<TValue, TError>(TValue value) => new(value); public static implicit operator Result<TValue, TError>(TError error) => new(error); } 关键改进:通过隐式操作符简化类型转换: // 优化前 return ; public static implicit operator EndpointResult<TValue, TError>(Result<TValue, TError> result new EndpointResult<TValue, TError>(TypedResults.Ok(result.Value)) : new EndpointResult<TValue

    21110编辑于 2025-06-30
领券