在.net下打造mongoDb基于官方驱动最新版本
还是一如既往先把结构图放出来,上上个版本添加了redis的缓存,但是不满足我的需求,因为公司有项目要求是分布式所以呢,这里我就增加了mongoDb进行缓存分布式,好了先看结构图(1)。
总的来说比较蛋疼,因为从来没有使用过mongoDB,从安装,到转为windows服务,设置权限等等,好吧这都是题外话。
在写这个MongoDB版本的时候遇到的一些问题,我先总结下:
1.MongoDb版本是官网最新版3.4.4,官方驱动为2.4.3,首先我的项目是以GUID做为主键,在往MongonDB中插入时遇到的是将GUID生成了MongoDB的LUUID格式产生了这样的格式(2)并且和我的数据库不同(3)当然redis也不同(4)。
a)带着问题我们去解决查了文档发现原来因为bson的键要标识成GUID,并且格式要转为string,既然知道问题了就去解决找到我的GUID主键,如下图(5):
在主键上加上 [BsonId(IdGenerator = typeof(GuidGenerator)), BsonRepresentation(BsonType.String)]这段就可以了,看了下效果确实可以了(6)。
2.但是在测试过程中查询的时候却找不到,一查原来我的数据库redis的id值都不一样,这又是怎么回事?
b)原来mongoDB生成的GUID和C#生成的GUID的进制是不一样的,为了解决这个问题,Google了一下,找到了一个脚本,把这个js脚本放在mongoDB里面执行一下,然后生成的GUID就和数据库的一样了。如图(7):
然后生成的_id就和我数据redis的一样了。(8)(9)
解决完成这些问题后开始写自己的封装类。
希望大家多给出建议,博主也是第一次玩mongoDB,如果有好的学习资源也请推荐给博主。
第一步创建连接:
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace KuRuMi.Mio.DoMain.MongoDbCache.MongoDbCommon
{
public class MongoDbManager
{
private static IMongoDatabase db = null;
private static readonly object locker = new object();
/// <summary>
/// 使用单列模式创建连接
/// </summary>
/// <returns></returns>
public static IMongoDatabase CreateDb()
{
if (db == null)
{
lock (locker)
{
if (db == null)
{
MongoClient Client = new MongoClient(MongoDbConfig.Host);
db = Client.GetDatabase(MongoDbConfig.DataBase);
}
}
}
return db;
}
}
}
第二步创建DB:
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace KuRuMi.Mio.DoMain.MongoDbCache.MongoDbCommon
{
public class MongoDbBase
{
private IMongoDatabase db = null;
public IMongoDatabase Db { get => db; }
public MongoDbBase()
{
db = MongoDbManager.CreateDb();
}
}
}
然后呢献上自己的封装helper:
using KuRuMi.Mio.DoMain.MongoDbCache.MongoDbCommon;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks; namespace KuRuMi.Mio.DoMain.MongoDbCache.MongoDbCache
{
/// <summary>
/// MongoDb缓存
/// </summary>
public sealed class MongoDbCacheService : MongoDbBase
{
#region 同步
#region 增加
/// <summary>
/// 保存单个对象
/// </summary>
/// <param name="Root"></param>
/// <returns></returns>
public bool AddSignleObject<TAggregateRoot>(TAggregateRoot Root)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
collection.InsertOne(Root);
return true;
}
catch (Exception)
{
return false;
} }
/// <summary>
/// 批量保存多个对象
/// </summary>
/// <param name="Root"></param>
/// <returns></returns>
public bool AddManyObject<TAggregateRoot>(List<TAggregateRoot> Root)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
collection.InsertMany(Root);
return true;
}
catch (Exception)
{
return false;
} }
#endregion #region 删除
/// <summary>
/// 删除单个记录
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="parameter"></param>
/// <returns></returns>
public int DeleteSingleIndex<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
return (int)collection.DeleteOne(filter).DeletedCount;
}
catch (Exception e)
{
throw e;
}
}
#endregion #region 查询
/// <summary>
/// 查询单条记录
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="parameter"></param>
/// <returns></returns>
public TAggregateRoot FindSingleIndex<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
return collection.Find(filter).FirstOrDefault();
}
catch (Exception e)
{
throw e;
}
}
/// <summary>
/// 查询整个集合
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="filter"></param>
/// <returns></returns>
public List<TAggregateRoot> FindMany<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
return collection.Find(filter).ToList();
}
catch (Exception e)
{
throw e;
}
}
#endregion #region 更新
/// <summary>
/// 更新单个值
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="filter"></param>
/// <param name="field"></param>
/// <param name="parameter"></param>
/// <returns></returns>
public int UpdateSingle<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter, string name, string parameter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
var set = Builders<TAggregateRoot>.Update.Set(name, parameter);
return (int)collection.UpdateOne(filter, set).ModifiedCount;
}
catch (Exception e)
{
throw e;
}
}
/// <summary>
/// 更新多个值
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="filter"></param>
/// <param name="Root"></param>
/// <param name="property"></param>
/// <param name="replace"></param>
public int UpdateMany<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter, TAggregateRoot Root, List<string> property = null, bool replace = false)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
var type = Root.GetType();
//修改集合
var list = new List<UpdateDefinition<TAggregateRoot>>();
foreach (var propert in type.GetProperties())
{
if (propert.Name.ToLower() != "id")
{
try
{
if (property == null && property.Count < || property.Any(o => o.ToLower() == propert.Name.ToLower()))
{
var replaceValue = propert.GetValue(Root);
if (replaceValue != null)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
else if (replace)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
}
}
catch (Exception)
{
if (property == null)
{
var replaceValue = propert.GetValue(Root);
if (replaceValue != null)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
else if (replace)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
}
} }
}
if (list.Count > )
{
var builders = Builders<TAggregateRoot>.Update.Combine(list);
return (int)collection.UpdateOne(filter, builders).ModifiedCount;
}
return ;
}
catch (Exception e)
{
throw e;
}
}
#endregion
#endregion #region 异步
#region 增加
/// <summary>
/// 异步保存单个对象
/// </summary>
/// <param name="Root"></param>
/// <returns></returns>
public bool AddSignleObjectAsync<TAggregateRoot>(TAggregateRoot Root)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
collection.InsertOneAsync(Root);
return true;
}
catch (Exception)
{
return false;
} }
/// <summary>
/// 批量保存多个对象
/// </summary>
/// <param name="Root"></param>
/// <returns></returns>
public bool AddManyObjectAsync<TAggregateRoot>(List<TAggregateRoot> Root)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
collection.InsertManyAsync(Root);
return true;
}
catch (Exception)
{
return false;
} }
#endregion #region 删除
/// <summary>
/// 异步删除单个记录
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="parameter"></param>
/// <returns></returns>
public int DeleteSingleIndexAsync<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
return (int)collection.DeleteOneAsync(filter).Result.DeletedCount;
}
catch (Exception e)
{
throw e;
}
}
#endregion #region 查询
/// <summary>
/// 异步查询单条记录
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="parameter"></param>
/// <returns></returns>
public TAggregateRoot FindSingleIndexAsync<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
return collection.FindAsync(filter).Result.FirstOrDefault();
}
catch (Exception e)
{
throw e;
}
}
/// <summary>
/// 异步查询整个集合
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="filter"></param>
/// <returns></returns>
public List<TAggregateRoot> FindManyAsync<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
return collection.FindAsync(filter).Result.ToList();
}
catch (Exception e)
{
throw e;
}
}
#endregion #region 更新
/// <summary>
/// 异步更新单个值
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="filter"></param>
/// <param name="field"></param>
/// <param name="parameter"></param>
/// <returns></returns>
public int UpdateSingleAsync<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter, string name, string parameter)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
var set = Builders<TAggregateRoot>.Update.Set(name, parameter);
return (int)collection.UpdateOneAsync(filter, set).Result.ModifiedCount;
}
catch (Exception e)
{
throw e;
}
}
/// <summary>
///异步更新多个值
/// </summary>
/// <typeparam name="TAggregateRoot"></typeparam>
/// <param name="filter"></param>
/// <param name="Root"></param>
/// <param name="property"></param>
/// <param name="replace"></param>
public int UpdateManyAsync<TAggregateRoot>(Expression<Func<TAggregateRoot, bool>> filter, TAggregateRoot Root, List<string> property = null, bool replace = false)
{
try
{
var collection = Db.GetCollection<TAggregateRoot>(typeof(TAggregateRoot).Name);
var type = Root.GetType();
//修改集合
var list = new List<UpdateDefinition<TAggregateRoot>>();
foreach (var propert in type.GetProperties())
{
if (propert.Name.ToLower() != "id")
{
try
{
if (property == null && property.Count < || property.Any(o => o.ToLower() == propert.Name.ToLower()))
{
var replaceValue = propert.GetValue(Root);
if (replaceValue != null)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
else if (replace)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
}
}
catch (Exception)
{
if (property == null)
{
var replaceValue = propert.GetValue(Root);
if (replaceValue != null)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
else if (replace)
list.Add(Builders<TAggregateRoot>.Update.Set(propert.Name, replaceValue));
}
} }
}
if (list.Count > )
{
var builders = Builders<TAggregateRoot>.Update.Combine(list);
return (int)collection.UpdateOneAsync(filter, builders).Result.ModifiedCount;
}
return ;
}
catch (Exception e)
{
throw e;
}
}
#endregion
#endregion
}
}
最后是脚本文件:
function HexToBase64(hex) {
var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64 = "";
var group;
for (var i = 0; i < 30; i += 6) {
group = parseInt(hex.substr(i, 6), 16);
base64 += base64Digits[(group >> 18) & 0x3f];
base64 += base64Digits[(group >> 12) & 0x3f];
base64 += base64Digits[(group >> 6) & 0x3f];
base64 += base64Digits[group & 0x3f];
}
group = parseInt(hex.substr(30, 2), 16);
base64 += base64Digits[(group >> 2) & 0x3f];
base64 += base64Digits[(group << 4) & 0x3f];
base64 += "==";
return base64;
}
function Base64ToHex(base64) {
var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var hexDigits = "0123456789abcdef";
var hex = "";
for (var i = 0; i < 24;) {
var e1 = base64Digits.indexOf(base64[i++]);
var e2 = base64Digits.indexOf(base64[i++]);
var e3 = base64Digits.indexOf(base64[i++]);
var e4 = base64Digits.indexOf(base64[i++]);
var c1 = (e1 << 2) | (e2 >> 4);
var c2 = ((e2 & 15) << 4) | (e3 >> 2);
var c3 = ((e3 & 3) << 6) | e4;
hex += hexDigits[c1 >> 4];
hex += hexDigits[c1 & 15];
if (e3 != 64) {
hex += hexDigits[c2 >> 4];
hex += hexDigits[c2 & 15];
}
if (e4 != 64) {
hex += hexDigits[c3 >> 4];
hex += hexDigits[c3 & 15];
}
}
return hex;
}
function UUID(uuid) {
var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters
var base64 = HexToBase64(hex);
return new BinData(4, base64); // new subtype 4
}
function JUUID(uuid) {
var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters
var msb = hex.substr(0, 16);
var lsb = hex.substr(16, 16);
msb = msb.substr(14, 2) + msb.substr(12, 2) + msb.substr(10, 2) + msb.substr(8, 2) + msb.substr(6, 2) + msb.substr(4, 2) + msb.substr(2, 2) + msb.substr(0, 2);
lsb = lsb.substr(14, 2) + lsb.substr(12, 2) + lsb.substr(10, 2) + lsb.substr(8, 2) + lsb.substr(6, 2) + lsb.substr(4, 2) + lsb.substr(2, 2) + lsb.substr(0, 2);
hex = msb + lsb;
var base64 = HexToBase64(hex);
return new BinData(3, base64);
}
function CSUUID(uuid) {
var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters
var a = hex.substr(6, 2) + hex.substr(4, 2) + hex.substr(2, 2) + hex.substr(0, 2);
var b = hex.substr(10, 2) + hex.substr(8, 2);
var c = hex.substr(14, 2) + hex.substr(12, 2);
var d = hex.substr(16, 16);
hex = a + b + c + d;
var base64 = HexToBase64(hex);
return new BinData(3, base64);
}
function PYUUID(uuid) {
var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters
var base64 = HexToBase64(hex);
return new BinData(3, base64);
}
BinData.prototype.toUUID = function () {
var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs in older versions of the shell
var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12);
return 'UUID("' + uuid + '")';
}
BinData.prototype.toJUUID = function () {
var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs in older versions of the shell
var msb = hex.substr(0, 16);
var lsb = hex.substr(16, 16);
msb = msb.substr(14, 2) + msb.substr(12, 2) + msb.substr(10, 2) + msb.substr(8, 2) + msb.substr(6, 2) + msb.substr(4, 2) + msb.substr(2, 2) + msb.substr(0, 2);
lsb = lsb.substr(14, 2) + lsb.substr(12, 2) + lsb.substr(10, 2) + lsb.substr(8, 2) + lsb.substr(6, 2) + lsb.substr(4, 2) + lsb.substr(2, 2) + lsb.substr(0, 2);
hex = msb + lsb;
var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12);
return 'JUUID("' + uuid + '")';
}
BinData.prototype.toCSUUID = function () {
var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs in older versions of the shell
var a = hex.substr(6, 2) + hex.substr(4, 2) + hex.substr(2, 2) + hex.substr(0, 2);
var b = hex.substr(10, 2) + hex.substr(8, 2);
var c = hex.substr(14, 2) + hex.substr(12, 2);
var d = hex.substr(16, 16);
hex = a + b + c + d;
var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12);
return 'CSUUID("' + uuid + '")';
}
BinData.prototype.toPYUUID = function () {
var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs
var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12);
return 'PYUUID("' + uuid + '")';
}
BinData.prototype.toHexUUID = function () {
var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs
var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12);
return 'HexData(' + this.subtype() + ', "' + uuid + '")';
}
仓储层的调用:
using KuRuMi.Mio.DoMain.Model.Model;
using KuRuMi.Mio.DoMain.Model.Repositories;
using KuRuMi.Mio.DoMain.Repository.EFRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace KuRuMi.Mio.DoMain.Repository.ModelRepository
{
public class UserRepositoryImpl : RepositoryImpl<User>, IUserRepository
{
public KurumiMioDbContext context => lazy.Context as KurumiMioDbContext;
/// <summary>
/// 登录
/// </summary>
/// <param name="Email"></param>
/// <param name="PassWord"></param>
/// <returns></returns>
public string CheckUser(string Email, string PassWord)
{
try
{
User entity = null;
//MongoDb取
entity = Mongo.FindSingleIndex<User>(a => a.Email == Email);
if (entity == null)
{
//redis取
entity = Redis.RedisString.Value.StringGet<User>(Email);
}
if (entity == null)
{
//数据库取
string sql = "select Id,UserName,Password,email from [User] as a where a.Email ='{0}' and a.PassWord ='{1}'";
string select = string.Format(sql, Email, PassWord);
entity = context.user.SqlQuery(select).FirstOrDefault();
}
return entity.UserName;
}
catch (Exception e)
{
return "";
}
} /// <summary>
/// 保存
/// </summary>
/// <param name="aggregateRoot"></param>
public async override void Add(User aggregateRoot)
{
base.Add(aggregateRoot);
await Redis.RedisString.Value.StringSetAsync(aggregateRoot.Email, aggregateRoot);//保存一份到redis
Mongo.AddSignleObjectAsync(aggregateRoot);//保存一份到mongoDb
} /// <summary>
/// 注册
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public User GetAll(User info)
{
string sql = "select Id,UserName,Password,email from [User] as a where a.UserName ='{0}' and email ='{1}'";
string select = string.Format(sql, info.UserName, info.Email);
return context.user.SqlQuery(select).FirstOrDefault();
}
}
}
图1:

图2:

图3:

图4:

图5:

图6:

图7:

图8:

图9:

在.net下打造mongoDb基于官方驱动最新版本的更多相关文章
- MongoDB Python官方驱动 PyMongo 的简单封装
最近,需要使用 Python 对 MongodB 做一些简单的操作,不想使用各种繁重的框架.出于可重用性的考虑,想对 MongoDB Python 官方驱动 PyMongo 做下简单封装,百度一如既往 ...
- 基于官方驱动封装mongodb
还是一如既往先把结构图放出来,上上个版本添加了redis的缓存,但是不满足我的需求,因为公司有项目要求是分布式所以呢,这里我就增加了mongoDb进行缓存分布式,好了先看结构图(1). 总的来说比较蛋 ...
- 【转】Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本的开发环境(亲测)
http://blog.csdn.net/ccf19881030/article/details/9204801 很久以前使用博客园博主子龙山人的一篇博文<Cocos2d-x win7+vs20 ...
- Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本的开发环境(亲测)
写这篇博客时2D游戏引擎Cocos2d-x的最新版本为2.1.4,记得很久以前使用博客园博主子龙山人的一篇博文<Cocos2d-x win7+vs2010配置图文详解(亲测)>成功配置 ...
- ubuntu14.04下配置Java环境以及安装最新版本的eclipse
首先是配置JDK 步骤一:下载最新版本的JDK,链接:http://www.oracle.com/technetwork/java/javase/downloads/index.html 步骤二:首先 ...
- 使用MongoDB C#官方驱动操作MongoDB
想要在C#中使用MongoDB,首先得要有个MongoDB支持的C#版的驱动.C#版的驱动有很多种,如官方提供的,samus. 实现思路大都类似.这里我们先用官方提供的mongo-csharp-dri ...
- JBoss7官方下载最新版本
JBoss是全世界开发人员共同努力的成果.一个基于J2EE的开放源码的应用server. 由于JBoss代码遵循LGPL许可,能够在不论什么商业应用中免费使用它.而不用支付费用. 2006年,Jbos ...
- windows下 更新 android studio SDK 到最新版本 解决方案
一.设置代理信息 打开android studio>>File>>Settings>>Appearance&Behavion>>System S ...
- 【MongoDB】 基于C#官方驱动2.2版的封装类
一.前言 最近项目中要用到MongoDB,因此实现做了不少的调研.发现网上很多现有关于MongoDB C#官方驱动的调用方法都是基于1.8版本的,已经不是用了最新的2.2版本.因此我在基于C#官方驱动 ...
随机推荐
- 【Java 并发】详解 ThreadPoolExecutor
前言 线程池是并发中一项常用的优化方法,通过对线程复用,减少线程的创建,降低资源消耗,提高程序响应速度.在 Java 中我们一般通过 Exectuors 提供的工厂方法来创建线程池,但是线程池的最终实 ...
- 设计模式的征途—3.抽象工厂(Abstract Factory)模式
上一篇的工厂方法模式引入了工厂等级结构,解决了在原来简单工厂模式中工厂类职责太重的原则,但是由于工厂方法模式的每个工厂只生产一类产品,可能会导致系统中存在大量的工厂类,从而增加系统开销.那么,我们应该 ...
- Laravel5中Cookie的使用
今天在Laravel框架中使用Cookie的时候,碰到了点问题,自己被迷糊折腾了半多小时.期间研究了Cookie的实现类,也在网站找了许多的资料,包括问答.发现并没有解决问题.网上的答案都是互相抄袭, ...
- hdu1151有向图的最小顶点覆盖
有向图的最小路径覆盖=V-二分图最大匹配. Consider a town where all the streets are one-way and each street leads from o ...
- 二分图的最大匹配——最大流EK算法
序: 既然是个图,并且求边数的最大值.那么这就可以转化为网络流的求最大流问题. 只需要将源点与其中一子集的所有节点相连,汇点与另一子集的所有节点相连,将所有弧的流量限制置为1,那么最大流 == 最大匹 ...
- matlab笔记(1) 元胞结构cell2mat和num2cell
摘自于:https://zhidao.baidu.com/question/1987862234171281467.html https://www.zybang.com/question/dcb09 ...
- 关于WordPress搬家方法步骤的整理
最近准备更换自己的博客服务器,所以需要将原来服务器上的所有东西都搬到新的服务器.为了数据的安全,在网上找了很多的资料.现在整理一下整个搬家过程的操作步骤.下面进入正题: 1.测试环境这次我使用的示例服 ...
- poj 1056 IMMEDIATE DECODABILITY 字典树
题目链接:http://poj.org/problem?id=1056 思路: 字典树的简单应用,就是判断当前所有的单词中有木有一个是另一个的前缀,直接套用模板再在Tire定义中加一个bool类型的变 ...
- hdu2059 龟兔赛跑 DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2059 虽然 知道是DP ,刚开始一直没有想出状态转移方程. 刚开始的思路就是定义dp[i]表示到达第i ...
- BM25和Lucene Default Similarity比较 (原文标题:BM25 vs Lucene Default Similarity)
原文链接: https://www.elastic.co/blog/found-bm-vs-lucene-default-similarity 原文 By Konrad Beiske 翻译 By 高家 ...