unsafe static httpUtility() { urlMap = new fixedMap(unmanaged.GetStatic(256 >> 3, true)); urlMap.Set('0', 10); urlMap.Set('A', 26); urlMap.Set('a', 26); urlMap.Set('('); urlMap.Set(')'); urlMap.Set('*'); urlMap.Set('-'); urlMap.Set('.'); urlMap.Set('!'); urlMap.Set('_'); }
/// <summary> /// 注销TCP服务信息 /// </summary> /// <param name="identity">TCP服务端标识</param> /// <param name="service">TCP服务信息</param> /// <returns>TCP服务端口信息集合信息是否被修改</returns> private unsafe bool removeRegister(indexIdentity identity, services service) { int count = (service.Hosts.Length + 7) >> 3, index = 0; byte * isRemove = stackalloc byte[count]; fixedMap removeMap = new fixedMap(isRemove, count); count = 0; indexIdentity hostIdentity; foreach (host host in service.Hosts) { if (hostClients.TryGetValue(host, out hostIdentity) && hostIdentity.Equals(identity) == 0) { removeMap.Set(index); } else { ++count; } ++index; } if (count == service.Hosts.Length) { return(false); } hashString serviceName = service.Name; if (count == 0) { foreach (host host in service.Hosts) { hostClients.Remove(host); } service.Hosts = nullValue <host> .Array; return(true); } host[] hosts = new host[count]; count = index = 0; foreach (host host in service.Hosts) { if (removeMap.Get(index++)) { hostClients.Remove(host); } else { hosts[count++] = host; } } service.Hosts = hosts; serviceCache[serviceName] = service; return(true); }
/// <summary> /// DataTable包装 /// </summary> /// <param name="table"></param> /// <param name="builder">数据流包装器</param> private unsafe void from(DataTable table, dataWriter builder) { int index = 0; columnNames = new string[table.Columns.Count]; fixed(byte *columnFixed = columnTypes = new byte[columnNames.Length]) { byte *columnIndex = columnFixed; foreach (DataColumn column in table.Columns) { if (!typeIndexs.TryGetValue(column.DataType, out *columnIndex)) { *columnIndex = 255; } ++columnIndex; columnNames[index++] = column.ColumnName; } fixed(byte *nullFixed = dbNull = new byte[(columnNames.Length *rowCount + 7) >> 3]) { fixedMap nullMap = new fixedMap(nullFixed); index = 0; foreach (DataRow row in table.Rows) { columnIndex = columnFixed; foreach (object value in row.ItemArray) { if (value == DBNull.Value) { nullMap.Set(index); } else { builder.Append(value, *columnIndex); } ++index; ++columnIndex; } } } } }
/// <summary> /// 文本分词 /// </summary> /// <param name="text">文本</param> /// <param name="length">文本长度</param> /// <returns>分词结果</returns> private unsafe list <subString> getWords(string text, int length) { fixed(char *textFixed = text) { simplified.Format(textFixed, length); int count = (length + 7) >> 3; byte * match = stackalloc byte[count]; fixedMap matchMap = new fixedMap(match, count, 0); list <subString> words = typePool <list <subString> > .Pop(); if (words == null) { words = new list <subString>(); } else if (words.Count != 0) { words.Clear(); } list <keyValue <int, int> > matchs = typePool <list <keyValue <int, int> > > .Pop() ?? new list <keyValue <int, int> >(); byte * charTypes = charTypePointer.Byte; subString matchWord = default(subString); for (char *start = textFixed, end = textFixed + length; start != end;) { if (*start == ' ') { *end = '?'; while (*++start == ' ') { ; } } else { * end = ' '; char *segment = start; if ((uint)(*start - 0x4E00) <= 0X9FA5 - 0x4E00) { while ((uint)(*++start - 0x4E00) <= 0X9FA5 - 0x4E00) { ; } if ((length = (int)(start - segment)) == 1) { words.Add(subString.Unsafe(text, (int)(segment - textFixed), 1)); } else { int startIndex = (int)(segment - textFixed); matchs.Empty(); matchWord.UnsafeSet(text, startIndex, length); wordTrieGraph.LeftRightMatchs(ref matchWord, matchs); if ((count = matchs.Count) != 0) { foreach (keyValue <int, int> value in matchs.UnsafeArray) { words.Add(subString.Unsafe(text, value.Key, value.Value)); matchMap.Set(value.Key, value.Value); if (--count == 0) { break; } } } int index = startIndex; for (int endIndex = startIndex + length; index != endIndex; ++index) { if (matchMap.Get(index)) { if ((count = index - startIndex) != 1) { words.Add(subString.Unsafe(text, startIndex, count)); } startIndex = index; } else { words.Add(subString.Unsafe(text, index, 1)); } } if ((index -= startIndex) > 1) { words.Add(subString.Unsafe(text, startIndex, index)); } } } else { byte type = charTypes[*start]; if (type == (byte)charType.OtherLetter) { while (charTypes[*++start] == (byte)charType.OtherLetter) { ; } } else { char *word = start; for (byte newType = charTypes[*++start]; newType >= (byte)charType.Letter; newType = charTypes[*++start]) { if (type != newType) { if (type != (byte)charType.Keep) { words.Add(subString.Unsafe(text, (int)(word - textFixed), (int)(start - word))); } type = newType; word = start; } } } words.Add(subString.Unsafe(text, (int)(segment - textFixed), (int)(start - segment))); } } } typePool <list <keyValue <int, int> > > .PushNotNull(matchs); if ((count = words.Count) == 0) { typePool <list <subString> > .PushNotNull(words); return(null); } return(words); } }